Beanstalk usage & lt ;? Phprequire_once (realpath (dirname (_ FILE __))... pheanstalkpheanstalk_init.php); class & nbsp; AppRemoteLib & nbsp; {var & nbsp; $ beanhost & nbsp; false; usage of var & nbsp 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);
?>
The problem is that, in the document, the tty parameter of the put command means -- Time to run-is an integer number, indicating the number of seconds that a worker can execute the job. This time is calculated by obtaining a job from a worker. If the worker fails Delete, release, or sleep the job within seconds. the job times out and the server releases the job. The minimum ttr value is 1. If the client is set to 0, the server increases it to 1 by default.
I set the tty parameter of put to 1, $ jobid = $ this-> beanhandle-> put ('some data', 1000 );
And $ job = $ this-> beanhandle-> reserve ($ timeout); sleep (10); delete a job after the fetch function is obtained, why can I still delete my job successfully? Shouldn't this job time out?
------ Solution --------------------
If the request times out, it will not be executed. delete or delete the request.