Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

jeyGey07's avatar

Queue timeout doesn't work

Hello, I use supervisor with the queues. When I dispatch a job, the timeout doesn't work (it is always 60 seconds). What parameter should I modify to modify the timeout? I tried in supervisor with:

queue:work --tries=1 --timeout=300 in supervisor

add public $timeout = 300 in the job.

add a parameter in the config file config/queue.php 'timeout' => 300.

I am using Laravel 8. I really need help please. Thank you

0 likes
15 replies
Sinnbeck's avatar

Try checking max_execution_time in php.ini for cli Be aware that you most likely have one for cli and one for web (fpm)

jeyGey07's avatar

@Sinnbeck Thank you for your answer. It's doesn't work. I changed max_execution_time in apache2 and in cli but i still got the same error.

[2022-02-17 21:47:31] production.ERROR: App\Jobs\RebuildAvailabilities has been attempted too many times or run too long. The job may have previously timed out. {"exception":"[object] (Illuminate\Queue\MaxAttemptsExceededException(code: 0): App\Jobs\RebuildAvailabilities has been attempted too many times or run too long. The job may have previously timed out. at /var/www/welrdv/vendor/laravel/framework/src/Illuminate/Queue/Worker.php:750) [stacktrace] #0 /var/www/welrdv/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(504): Illuminate\Queue\Worker->maxAttemptsExceededException() #1 /var/www/welrdv/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(418): Illuminate\Queue\Worker->markJobAsFailedIfAlreadyExceedsMaxAttempts() #2 /var/www/welrdv/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(378): Illuminate\Queue\Worker->process() #3 /var/www/welrdv/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(172): Illuminate\Queue\Worker->runJob() #4 /var/www/welrdv/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(117): Illuminate\Queue\Worker->daemon() #5 /var/www/welrdv/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(101): Illuminate\Queue\Console\WorkCommand->runWorker() #6 /var/www/welrdv/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(36): Illuminate\Queue\Console\WorkCommand->handle() #7 /var/www/welrdv/vendor/laravel/framework/src/Illuminate/Container/Util.php(40): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}() #8 /var/www/welrdv/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(93): Illuminate\Container\Util::unwrapIfClosure() #9 /var/www/welrdv/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(37): Illuminate\Container\BoundMethod::callBoundMethod() #10 /var/www/welrdv/vendor/laravel/framework/src/Illuminate/Container/Container.php(653): Illuminate\Container\BoundMethod::call() #11 /var/www/welrdv/vendor/laravel/framework/src/Illuminate/Console/Command.php(136): Illuminate\Container\Container->call() #12 /var/www/welrdv/vendor/symfony/console/Command/Command.php(298): Illuminate\Console\Command->execute() #13 /var/www/welrdv/vendor/laravel/framework/src/Illuminate/Console/Command.php(121): Symfony\Component\Console\Command\Command->run() #14 /var/www/welrdv/vendor/symfony/console/Application.php(1005): Illuminate\Console\Command->run() #15 /var/www/welrdv/vendor/symfony/console/Application.php(299): Symfony\Component\Console\Application->doRunCommand() #16 /var/www/welrdv/vendor/symfony/console/Application.php(171): Symfony\Component\Console\Application->doRun() #17 /var/www/welrdv/vendor/laravel/framework/src/Illuminate/Console/Application.php(94): Symfony\Component\Console\Application->run() #18 /var/www/welrdv/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(129): Illuminate\Console\Application->run() #19 /var/www/welrdv/artisan(37): Illuminate\Foundation\Console\Kernel->handle() #20 {main} "}

Snapey's avatar

@jeyGey07 how do you know its hitting the limit? It says it may have timed out, but it could be other faults also

jeyGey07's avatar

@Snapey I don't know but I know that the jobs lasts more than 60s. Jobs that last less time work. It's just a guess. Do you have an idea ?

jeyGey07's avatar

and job stops after 60s. (for the longest)

jeyGey07's avatar

Any ideas ? I really need to find a solution? Please :(

Snapey's avatar

Assuming this is being run by a queue worker, check the php.ini being used by that instance of the worker has the longer execution time.

Also, if you make any changes in code, make sure you restart the worker(s)

jeyGey07's avatar

In etc/php/8.0/apache2/php.ini and etc/php/8.0/cli/php.ini

max_exceution_time = 500

In Jobs in laravel

public $timeout = 300;

public $tries = 1;

In supervisor (worker conf)

queue:work --queue=availabilities --timeout=300 --tries=1

I restarted apache2 and supervisor.

When I execute job, after 90 seconds (it's not 60 seconds now), I get the error: App\Jobs\RebuildAvailabilities has been attempted too many times or run too long. The job may have previously timed out

I'm still stuck, I don't understand..

Snapey's avatar

@jeyGey07 any chance the job is running out of memory? (this would lead to termination of the job with no error)

jeyGey07's avatar

I don't know how to see this. But when I run it with a command everything goes fine, it fails when I go through the queue

jeyGey07's avatar

in command mode: 109s in queue mode: stops after 91 seconds

moreover (but that's another problem, on production the actions take 10 times longer than on my dev environment)

Snapey's avatar

@jeyGey07 i assume you are crawling the database or updating a lot of records and maybe your database is remote?

I can't immediately answer the max execution time, but it would be definitely worth optimising the operations

jeyGey07's avatar

I'm using ES and it's on another machine. but yes I would try to optimize the delay of the function. I have to fix the timeout problem. You don't have another idea ? Could it be a library bug?

BlackOnyx's avatar

What's the value for retry_after in config/queue.php for the connection used?

If it's set to 90 what you were seeing would happen. From the docs: "This option specifies how many seconds the queue connection should wait before retrying a job that is being processed. For example, if the value of retry_after is set to 90, the job will be released back onto the queue if it has been processing for 90 seconds without being released or deleted"

In summary, if retry_after is set to 90, the job would stop after 90 seconds and be released back into the queue. And, since the worker was set to only 1 try with --tries=1, it would go something like this: 90 seconds pass, the jobs is thrown back into the queue, it tries to execute again but finds it's the second time running the job, throws "... has been attempted too many times or run too long. The job may have previously timed out" error.

1 like

Please or to participate in this conversation.