Laravel queue is quite easy to setup and use.
But how it actually work is seem like a mystery and undocumented
There are some pitfall that beginner usually fall into, the common one is stucking
1. Job opened a resource that does not timeout properly
A typical example is Guzzle / cURL with default settings.
Laravel queue worker works in PHP CLI that have max_execution_time = 0 (Unlimited)
Guzzle without timeout easily stuck queue forever. Add timeout parameters to any calls within your Job to prevent this problem.
<?php $httpClient = new \GuzzleHttp\Client(); $response = $httpClient->request('GET', 'http://...', [ 'timeout' => 30, 'read_timeout' => 30, 'connect_timeout' => 30, ])
2. Job opened resources/used memory that does not release properly
A typical example is functions calling TCPDF, PHPExcel, PHPSpreadSheet… memory demanding libraries
Laravel queue worker does not restart PHP process after each Job executed.
If memory is not freed properly, the PHP process quickly run out-of-memory and slow-down & freeze may happen.
It is a well-known memory leak problem. Refer to the libraries docs to see how to de-initialize them properly
3. Laravel Job “timeout” does not work without PHP 7.1+ and pcntl extension.
In fact, it does not work at all without meeting that requirement, see: https://github.com/laravel/framework/issues/19584
pcntl extension is however, does not work nor included in any Windows version of PHP (Including XAMPP, Official Binary Releases… etc)
You should not rely on this feature unless you meets all those requirements.