Performance: Queue workers
Queue workers affect how background tasks are processed, impacting server responsiveness and user experience by offloading work from the main request cycle.
Jump into concepts and practice - no test required
php artisan queue:work --sleep=0 --tries=3 --timeout=60
php artisan queue:work --sleep=3 --tries=1
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Single slow queue worker with sleep | 0 (server-side) | 0 | 0 | [X] Bad |
| Multiple fast queue workers with zero sleep | 0 (server-side) | 0 | 0 | [OK] Good |
| Long-running worker without restart | 0 (server-side) | 0 | 0 | [!] |
| Worker with memory limit and restart | 0 (server-side) | 0 | 0 | [OK] Good |
php artisan queue:work.dispatch(new SendEmailJob($user));
php artisan queue:work --queue=emails --delay=abc
php artisan queue:work --queue=emails and php artisan queue:work --queue=notifications runs two workers, each for one queue. Run one command: php artisan queue:work --queue=emails,notifications tries to combine queues in one worker, which processes them together, not separately. Run one command: php artisan queue:work without options processes default queue only. Run two commands: php artisan queue:listen --queue=emails and php artisan queue:listen --queue=notifications uses deprecated 'queue:listen'.