READY : Tasks that need to be processed immediately, automatically become the current task when the DELAYED task expires;
DELAYED : delay the implementation of the task, when the consumer to deal with the task, you can use the message back to the DELAYED queue delayed execution;
RESERVED : Has been consumer acquisition, the ongoing task. Beanstalkd is responsible for checking whether the task is completed within the time-to-run (TTR)
BURIED : Reserved tasks: The task will not be executed, it will not disappear unless someone “kicked” it back in the queue;
DELETED : The message is completely deleted. Beanstalkd no longer maintain these messages.
Install Beanstalkd
1
$ sudo aptitude install -y beanstalkd
Auto start
1
$ vim /etc/default/beanstalkd
1 2 3 4 5 6 7 8 9 10 11
## Defaults for the beanstalkd init script, /etc/init.d/beanstalkd on ## Debian systems.
# You can use BEANSTALKD_EXTRA to pass additional options. See beanstalkd(1) # for a list of the available options. Uncomment the following line for # persistent job storage. BEANSTALKD_EXTRA="-b /var/lib/beanstalkd" START=yes
Pay attention to this place "-b /var/lib/beanstalkd" which can recovery your queue data after machine shutdown suddenly. Beanstalkd will find its binlog files which is 10M max size default under this directory
Using Beanstalkd php client
I’m using the php client pda/pheanstalk It needs php5.3+
<?php require 'vendor/autoload.php'; use Pheanstalk\Pheanstalk;
$level = 1;// most urgent: 0, least urgent: 4294967295 $delay = 10; //10s $ttl = 10; //10s
$pheanstalk = new Pheanstalk('127.0.0.1');
// Create a job then put into the tube named testtube $jobId = $pheanstalk ->useTube('testtube') ->put( "job payload goes here\n", $level, $delay, $ttl );
echo ($jobId) . "\n";
// The consumer watchs the tube, waits a ready job $job = $pheanstalk ->watch('testtube') ->reserve();
// Deal with the data echo $job->getData(); // Delete the job after logic success $pheanstalk->delete($job);