Installation:
composer require anglemx/pheanstalk-bundle
Add to config/bundles.php:
Angle\PheanstalkBundle\PheanstalkBundle::class => ['all' => true],
Configure (config/packages/angle_pheanstalk.yaml):
angle_pheanstalk:
connections:
default:
host: '127.0.0.1'
port: 11300
timeout: 10
First Use Case:
Inject PheanstalkInterface into a service/controller:
use Angle\PheanstalkBundle\Client\PheanstalkInterface;
public function __construct(private PheanstalkInterface $pheanstalk) {}
// Producer
$this->pheanstalk->useTube('jobs')->put('Process user:123');
// Worker (CLI)
$job = $this->pheanstalk->watch('jobs')->reserve();
$job->delete();
Job Production:
$this->pheanstalk
->useTube('high_priority')
->put('data', 0, 3600, 1024, 'unique-job-id'); // priority, delay, ttr, size
Job Consumption (Worker):
$job = $this->pheanstalk
->watch('high_priority')
->ignore('low_priority')
->reserve(10); // timeout
if ($job) {
$data = $job->getData();
$job->delete(); // or release() if retry
}
Batched Processing:
for ($i = 0; $i < 10; $i++) {
$job = $this->pheanstalk->reserve();
if (!$job) break;
// Process job...
}
PheanstalkEvents (e.g., JobReservedEvent) for cross-cutting logic.angle_pheanstalk.profiler: true to monitor queue metrics.angle:pheanstalk:list-tubes or angle:pheanstalk:peek-job for debugging.// services.yaml
services:
App\Service\JobProcessor:
arguments:
$pheanstalk: '@angle.pheanstalk'
Connection Timeouts:
timeout (10s) may be too short for slow workers. Increase via config.->connect() explicitly if reusing connections across requests.Job Stuck in "Ready" State:
ttr (time-to-run) isn’t too short. Default is 1 second in Pheanstalk.->release($job, 60) to retry with a longer delay.Symfony Event Order:
JobReservedEvent triggers post-reserve).php bin/console angle:pheanstalk:stats # Server stats
php bin/console angle:pheanstalk:list-tubes # Tube contents
Custom Proxy:
Override Angle\PheanstalkBundle\Client\Proxy\PheanstalkProxy to:
angle_pheanstalk:
proxy_class: App\Proxy\CustomPheanstalkProxy
Event Subscribers:
use Angle\PheanstalkBundle\Event\JobReservedEvent;
public static function getSubscribedEvents(): array
{
return [
JobReservedEvent::class => 'onJobReserved',
];
}
Connection Management:
$connection = $this->pheanstalk->getConnection();
$connection->useTube('custom')->put(...);
Multiple Connections:
angle_pheanstalk:
connections:
primary: { host: '127.0.0.1', port: 11300 }
backup: { host: '10.0.0.1', port: 11300 }
Inject via angle.pheanstalk.primary or angle.pheanstalk.backup.
Environment-Specific:
Use %env(BEANSTALK_HOST)% in config for dynamic values.
->peek() + ->delete() loops instead of ->reserve() in tight loops.->watch() calls.How can I help you explore Laravel packages today?