PHP8.1.21版本已发布
vue8.1.21版本已发布
jquery8.1.21版本已发布

beanstalk的使用有关问题

原创
2016-06-13 11:55:51 910浏览

beanstalk的使用问题

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);
?>


问题是这样,资料上说put命令的tty参数的意思是  --time to run—是一个整形数,表示允许一个worker执行该job的秒数。这个时间将从一个worker 获取一个job开始计算。如果该worker没能在 秒内删除、释放或休眠该job,这个job就会超时,服务端会主动释放该job。最小ttr为1。如果客户端设置了0,服务端会默认将其增加到1。

我设置put的tty的参数为1,$jobid = $this->beanhandle->put('some data', 1000, 0,1 );
并且在fetch函数中获取完成之后$job = $this->beanhandle->reserve($timeout); sleep(10);延迟了10秒才删除job,为什么我的job还是可以删除成功,不是应该这个job会超时吗?
------解决方案--------------------
超时就不执行,删除还是删除
声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。