时间:2021-07-01 10:21:17 帮助过:21人阅读
require_once(realpath(dirname(__FILE__)).'/../pheanstalk/pheanstalk_init.php');
class AppRemoteLib {
var $beanhost = false;
var $beanport = false;
var $beanhandle = false;
function openqueue($host, $port) {
if ($this->beanhost || $this->beanport) return false;
$this->beanhost = $host;
$this->beanport = $port;
$this->beanhandle = new Pheanstalk($host, $port);
if (!$this->beanhandle) return false;
return true;
}
public function putrequest()
{
try {
$this->beanhandle->useTube('test');
$jobid = $this->beanhandle->put('some data', 1000, 0,1 );
} catch (Exception $e) {
$jobid = false;
}
return $jobid;
}
public function fetch($tube, $timeout=0) {
try {
$this->beanhandle->watch($tube);
$job = $this->beanhandle->reserve($timeout);
} catch (Exception $e) {
return false;
}
if (!$job) return false;
var_dump($job);
sleep(10);
try {
$this->beanhandle->delete($job);
} catch (Exception $e) {
return false;
}
return $job;
}
private function watch($tube) {
$this->beanhandle->watch($tube);
}
private function fetchall($timeout=0) {
try {
$job = $this->beanhandle->reserve($timeout);
if (!$job) return false;
$this->beanhandle->delete($job);
} catch (Exception $e) {
}
return $job;
}
}
$appremotelib = new AppRemoteLib();
$appremotelib->openqueue("192.168.19.128", "11911");
$appremotelib->putrequest();
$job = $appremotelib->fetch('test', 2);
?>