yii-dbeanstalkd Distributed wrapper for beanstalkd client with basic weighted algorithm and graceful handling of connection failures

  1. Requirements
  2. Usage
  3. Resources

Distributed wrapper for yii for davidpersson's beanstalkd client

This project differs from other yii extensions in that it provides a very trivial method of managing multiple, distributed beanstalkd servers. Other projects, or classes, differ in that they build upon existing implementations but do not offer any method of failover or recovery from a server failure.

Since a single server going down would cause complete failure this must, at the very least:

  1. be aware of multiple servers/connections
  2. be able to choose between them based upon a simple weighted algorithm
  3. be able to use a different server if one is unavailable In the event of a server failure, this class makes no attempt to ensure enqueued items are not lost since. This will allow the user to enqueue in another server and keep going.


  • davidpersson's beanstalkd client to be added to your yii project
  • modifications to config files to support these additions
Add davidpersson's beanstalkd client

Clone davidpersson's library and place it in the extensions folder of your yii application, in a folder named 'beanstalk'.

Modify config files to support these additions

Ensure that the Beanstalk.php class from this project has been placed in your components folder.

Ensure this line has been added under the aliases section of your yii config file:

        // davidpersson's library has been installed to extensions/beanstalk folder
        'Beanstalk'=> 'application.extensions.beanstalk.src',

Ensure these lines have been added to the components section of your yii config file:

                    // array of connections/tubes
                    // array of connections/tubes


Producer example
 * connect to a server (determines by weight or selects only existing server::
$client = Yii::app()->beanstalk->getClient();

 * alternatively, one can connect to a server by name:
//$client = Yii::app()->beanstalk->getClient('server1');


//echo "Tube used: {$client->listTubeUsed()}.\n";

$jobDetails = [
    'application'=>'beanstalk test',
    'payload'=>'performing a test on: '.date('Y-m-d H:i:s'),
$jobDetailString = json_encode($jobDetails);

$ret = $client->put(
    0, // priority
    0, // do not wait, put in immediately
    90, // will run within n seconds
    $jobDetailString // job body

echo "Added $jobDetailString to queue.\n";
echo "Return was: $ret.\n";

Consumer Examples
$peek = Yii::app()->beanstalk->getClient();

$job = $peek->reserve(5);

$result = touch($job['body']);
$consumer = Yii::app()->beanstalk->getClient();

    $job = $consumer->reserve();
    $result = touch($job['body']);

    if( $result )
        // do something with the job request
        echo "Done...\n";
        // handle failure here
        echo "Burying...\n";



Great related tools
1 0
Yii Version: 1.1
License: MIT
Category: Others
Developed by: cottonaf
Created on: May 20, 2015
Last updated: 5 years ago


show all

Related Extensions