php beanstalk 客户端,beanstalk的使用有关问题

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会超时吗?

------解决方案--------------------

超时就不执行,删除还是删除

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值