beanstalk的使用有关问题

WBOY
Release: 2016-06-13 11:55:51
Original
1118 people have browsed it

beanstalk的使用问题

<?php<br />require_once(realpath(dirname(__FILE__)).'/../pheanstalk/pheanstalk_init.php');<br /><br />class AppRemoteLib {<br />	var $beanhost = false;<br />	var $beanport = false;<br />	var $beanhandle = false;<br />	<br />	function openqueue($host, $port) {<br />		if ($this->beanhost || $this->beanport) return false;<br />		$this->beanhost = $host;<br />		$this->beanport = $port;<br />		$this->beanhandle = new Pheanstalk($host, $port);<br />		if (!$this->beanhandle) return false;<br />		return true;<br />	}<br />	<br />	public function putrequest()<br />	{<br />		try {<br />			$this->beanhandle->useTube('test');<br />			$jobid = $this->beanhandle->put('some data', 1000, 0,1 );<br />		} catch (Exception $e) {<br />			$jobid = false;<br />		}<br />		return $jobid;<br />	}<br /><br />	public function fetch($tube, $timeout=0) {<br />		try {<br />			$this->beanhandle->watch($tube);<br />			$job = $this->beanhandle->reserve($timeout);<br />		} catch (Exception $e) {<br />			return false;<br />		}<br />		if (!$job) return false;<br />		var_dump($job);<br />		sleep(10);<br />		try {<br />			$this->beanhandle->delete($job);<br />		} catch (Exception $e) {<br />			return false;<br />		}<br />		return $job;<br />	}<br />	private function watch($tube) {<br />		$this->beanhandle->watch($tube);<br />	}<br />	private function fetchall($timeout=0) {<br />		try {<br />			$job = $this->beanhandle->reserve($timeout);<br />			if (!$job) return false;<br />			$this->beanhandle->delete($job);<br />		} catch (Exception $e) {<br />		}<br />		return $job;<br />	}<br /><br />}<br /><br />$appremotelib = new AppRemoteLib();<br />$appremotelib->openqueue("192.168.19.128", "11911");<br />$appremotelib->putrequest();<br />$job = $appremotelib->fetch('test', 2);<br />?>
Copy after login


问题是这样,资料上说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会超时吗?
------解决方案--------------------
超时就不执行,删除还是删除

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!