Ways to Dispatch Laravel Work Process

With minimum configuration according to this stackoverflow post:

nohup php artisan queue:work --daemon &

This will run the queue:work process in the background and will not stop if an user logs out. The output of the process will be deposited into a file entitled nohup.out in the directory where you run the command. To redirect the output to /dev/null or Laravel log :

nohup php artisan queue:work --daemon > /dev/null 2>&1 &
nohup php artisan queue:work --daemon > app/storage/logs/laravel.log &

To kill the process: find pid by ps -ef |grep artisan. Then you can run kill [pid].   You will need to respawn new workers each time code changes.

For Production servers, Laravel suggested using a process monitor, Linux Supervisor, that can detect when your queue:work processes exit and automatically restart them. This would be good for system crashes.

Here’s the link to the documentation: https://laravel.com/docs/8.x/queues#supervisor-configuration

 

Using Laravel Task Schedulerhttps://laravel.com/docs/5.7/scheduling#scheduling-artisan-commands

Schedule cron job:

crontab -e
* * * * * cd /path_to_project && php artisan schedule:run >> /dev/null 2>&1

Cron will call the Laravel command scheduler every minute.

The 4 * means:

  • 1: Minute (0-59)
  • 2: Hours (0-23)
  • 3: Day (0-31)
  • 4: Month (0-12 [12 == December])
  • 5: Day of the week(0-7 [7 or 0 == Sunday])