Official Doc: https://laravel.com/docs/5.3/queues#introduction
Command to build job class:
1 |
php artisan make:job SendReminderEmail |
Command to dispatch job:
1 |
dispatch(new FakePriceData(10)); |
Command to execute start queue worker:
1 |
php artisan queue:work database --queue=daemon --tries=3 |
For Laravel 5.2 or older version
1 2 3 4 5 |
//Process the first job only php artisan queue:work //Continue to process all jobs php artisan queue:listen |
https://stackoverflow.com/questions/37207290/laravel-queue-only-run-one-job
Run queue worker in background
1 2 3 4 5 6 7 8 |
//Execute queue in background nohup php artisan queue:work --daemon > storage/logs/nohup_queue.log 2>&1 & //Find existing nohup jobs jobs -l //Kill nohup process kill -9 12345 |
- https://stackoverflow.com/questions/28623001/how-to-keep-laravel-queue-system-running-on-server
- https://www.opencli.com/linux/nohup-background-execute-command
Note:
- Every time related scripts are changed, the queue worker must be restarted or the job will always read the script in some cache.
- Don’t use database to save queue data. Performance is bad and there must be some bugs during data conversion. Some data could be missing when sending emails.