To use Beanstalkd as the queue driver in Laravel, you need to follow these steps:
composer require pda/pheanstalk laravel/queue
.env
file in your Laravel project and update the QUEUE_CONNECTION
value to beanstalkd
.QUEUE_CONNECTION=beanstalkd
config/queue.php
file: Laravel comes with a default configuration file for the queue. Open the config/queue.php
file and update the beanstalkd
section with the following configuration:'beanstalkd' => [
'driver' => 'beanstalkd',
'host' => '127.0.0.1',
'queue' => 'default',
'ttr' => 60,
],
Here, you can modify the host, queue, and ttr (Time-To-Run) values as per your requirements.
php artisan queue:work --queue=your-queue-name
Replace your-queue-name
with the name of the queue you want to process. If you have multiple queues, separate them with commas.
dispatch
helper function or the Jobs
class in Laravel. Here's an example:dispatch(function () {
// Your job logic here
});
Or
dispatch(new YourJobClass());
That's it! Laravel will connect to Beanstalkd and process the queued jobs in the background. You can check the Laravel logs or the Beanstalkd logs for any errors or job-specific information.