for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Zenstruck\Queue\Driver;
use Pheanstalk\Job as PheanstalkJob;
use Pheanstalk\PheanstalkInterface;
use Zenstruck\Queue\Driver;
use Zenstruck\Queue\Job;
use Zenstruck\Queue\Payload;
/**
* @author Kevin Bond <[email protected]>
*/
final class BeanstalkdDriver implements Driver
{
private $client;
private $tube;
* @param PheanstalkInterface $client
* @param string $tube
public function __construct(PheanstalkInterface $client, $tube)
$this->client = $client;
$this->tube = $tube;
}
* {@inheritdoc}
public function push(Payload $payload)
$this->client->useTube($this->tube);
$this->client->put(json_encode($payload));
public function pop()
$rawJob = $this->client->watchOnly($this->tube)->reserve(0);
if (!$rawJob instanceof PheanstalkJob) {
return null;
if (null === $payload = Payload::fromJson($rawJob->getData())) {
// can't handle - requeue
$this->client->release($rawJob, 2048);
$stats = $this->client->statsJob($rawJob);
$attempts = isset($stats['reserves']) ? (int) $stats['reserves'] : 1;
return new Job($payload, $attempts, $rawJob);
public function release(Job $job)
$this->client->release($job->id());
public function delete(Job $job)
$this->client->delete($job->id());