BeansClient is a PHP8 client for beanstalkd work queue with thorough unit-testing.
Library uses PSR-4 autoloader standard and always has 100% tests coverage.
Library gives you a simple way to provide your own Socket implementation, in cases when you need to log requests and
responses or to proxy traffic to non-standard transport.
BeansClient supports whole bunch of commands and responses specified
in protocol for version 1.12
- Well tested.
- Supports UNIX sockets.
- Actively maintained.
- Predictable (does not throw exception in any situation, hello
pheanstalk
🤪). - PHP8 support.
- PHP 8.0+
- beanstalkd 1.12+
Install with composer
composer require xobotyi/beansclient
<?php
use xobotyi\beansclient\Beanstalkd;
use xobotyi\beansclient\Client;
use xobotyi\beansclient\Socket\SocketsSocket;
$sock = new SocketsSocket(host: 'localhost', port: 11300, connectionTimeout: 2);
$client = new Client(socket: $sock, defaultTube: 'myAwesomeTube');
## ##
# PRODUCER #
## ##
$job = $client->put("job's payload", delay: 2);
if($job['state'] === Beanstalkd::JOB_STATE_DELAYED) {
echo "Job {$job['id']} is ready to be reserved within 2 seconds\n";
}
## ##
# WORKER #
## ##
$client->watchTube('myAwesomeTube2');
$job = $client->reserve();
if ($job) {
echo "Hey, i received first {$job['payload']} of job with id {$job['id']}\n";
$client->delete($job['id']);
echo "And i've done it!\n";
}
else {
echo "So sad, i have nothing to do";
}
echo "Am I still connected? \n" . ($client->socket()->isConnected() ? 'Yes' : 'No') . "\n";