Beanstalk usage problems

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.