Pheanstalk is a pure PHP 5.2+ client for the beanstalkd workqueue. It has been actively developed, and used in production by many, since late 2008.
Created by Paul Annesley, Pheanstalk is rigorously unit tested and written using encapsulated, maintainable object oriented design. Community feedback, bug reports and patches has led to a stable 1.0.0 release in 2010.
beanstalkd up to the latest version 1.4 is supported. All commands and responses specified in the protocol documentation for beanstalkd 1.3 are implemented.
Add the following lines to your composer.json
requirements:
"require": {
"pda/pheanstalk": "dev-master"
}
<?php
// If you aren't using composer, register Pheanstalk class loader
require_once('pheanstalk_init.php');
$pheanstalk = new Pheanstalk('127.0.0.1');
// ----------------------------------------
// check service availability
$isBeanstalkdListening = $pheanstalk->getConnection()->isServiceListening(); //returns true|false
// ----------------------------------------
// producer (queues jobs)
$pheanstalk
->useTube('testtube')
->put("job payload goes here\n");
// ----------------------------------------
// worker (performs jobs)
$job = $pheanstalk
->watch('testtube')
->ignore('default')
->reserve();
echo $job->getData();
$pheanstalk->delete($job);
?>
There is a section of the test suite which depends on a running beanstalkd
at 127.0.0.1:11300, which was previously opt-in via --with-server
.
Since porting to PHPUnit, all tests are run at once. Feel free to submit
a pull request to rectify this.
# ensure you have PHPUnit
$ sudo pear channel-discover pear.phpunit.de
$ sudo pear channel-discover components.ez.no
$ sudo pear channel-discover pear.symfony.com
$ sudo pear install phpunit/PHPUnit
$ hash -r
# ensure you have Composer set up
$ wget http://getcomposer.org/composer.phar
$ php composer.phar install
$ phpunit
PHPUnit 3.7.10 by Sebastian Bergmann.
Configuration read from /Users/pda/code/pheanstalk/phpunit.xml.dist
................................................................. 65 / 79 ( 82%)
..............
Time: 0 seconds, Memory: 8.75Mb
OK (79 tests, 387 assertions)
- Paul Annesley
- Lachlan Donald
- Joakim Bick
- SlNPacifist
- leprechaun
- Peter McArthur
- robbiehudson
- Geoff Catlin
- srjlewis
- Lars Yencken
- Josh Butts
- Henry Smith
- Javier Spagnoletti
- .. more? Let me know if you're missing.
© Paul Annesley
Released under the The MIT License