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 />?>