Linux – Avoid php artisan queues : work : Queue Driver – Redis or Database (Laravel 5. 4)

Avoid php artisan queues : work : Queue Driver – Redis or Database (Laravel 5. 4)… here is a solution to the problem.

Avoid php artisan queues : work : Queue Driver – Redis or Database (Laravel 5. 4)

I

currently use the database as my queue driver, and I have Laravel 5.4 installed on my Windows 10 PC. To handle queues, I’ve been using PHP artisan queue:work, which is perfectly fine during development. Now that the project is fully ready to be deployed on a Linux server (dedicated) I’m not sure how to avoid running the command php artisan queue:work on the terminal to handle mail jobs?

I’ve deployed once in shared hosting and I used cron jobs, but now that I have dedicated servers I think I should be able to use something else to run jobs, and I’m also thinking about using Redis as a queue driver instead of a database as a queue driven

I need some advice on what is the best. And how to avoid using php artisan queue:work on dedicated servers? Do I need to write small scripts to ensure that the job runs in the background as a service.

Solution

The Laravel documentation covers supervisors.

See also: Laravel Supervisor configuration

The supervisor is a process monitor that ensures that your queue command (or any other command for that matter) is executed and restarted if it dies.

Edit:

See also: Supervisor documentation

Basically for CentOS, you can use yum:

yum install supervisor

Simple installation

// required for easy_install (if not installed already)
yum install python-setuptools     
 install supervisor
easy_install supervisor

or pips

pip install supervisor

After that it just creates your configuration (based on the example given in the Laravel docs), which is handled step by step:

Supervisor: creating-a-configuration-file

and create the service: Setup Supervisor

After that you can start the service:

service supervisord start

Related Problems and Solutions