How to call queue worker in background in laravel?

Member

by denis , in category: PHP Frameworks , 3 months ago

How to call queue worker in background in laravel?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by kadin , 3 months ago

@denis 

To call a queue worker in the background in Laravel, you can use the following command:

1
php artisan queue:work --daemon


This command will start a queue worker that will continuously process jobs from the queue in the background. You can also specify the queue connection and queue name by adding the --queue option:

1
php artisan queue:work --daemon --queue=your_queue_name


Alternatively, you can start a queue worker in the background using Supervisor. Supervisor is a process control system that allows you to monitor and control processes on Unix-like operating systems. Here's how you can set up Supervisor to run a queue worker:

  1. Install Supervisor:
1
sudo apt-get install supervisor


  1. Create a Supervisor configuration file for your queue worker:
1
sudo nano /etc/supervisor/conf.d/your_queue_worker.conf


  1. Add the following configuration to the file:
1
2
3
4
5
6
7
[program:your_queue_worker]
command=php /path-to-your-laravel-project/artisan queue:work --daemon --queue=your_queue_name
directory=/path-to-your-laravel-project
autostart=true
autorestart=true
stderr_logfile=/var/log/your_queue_worker.err.log
stdout_logfile=/var/log/your_queue_worker.out.log


  1. Reload Supervisor to load the new configuration:
1
2
sudo supervisorctl reread
sudo supervisorctl update


  1. Start the Supervisor process for your queue worker:
1
sudo supervisorctl start your_queue_worker


Now your queue worker will be running in the background and processing jobs from the specified queue.