Home » Php » php – Laravel 4 Queue:listen times out

php – Laravel 4 Queue:listen times out

Posted by: admin July 12, 2020 Leave a comment

Questions:

I ran php artisan queue:listen and after about 27 minutes, it stops processing any more jobs. In my error log, I see the error:

exception 'Symfony\Component\Process\Exception\RuntimeException' with message 'The process timed out.' in /var/www/l4site/vendor/symfony/process/Symfony/Component/Process/Process.php:413
Stack trace:
#0 /var/www/l4site/vendor/symfony/process/Symfony/Component/Process/Process.php(201): Symfony\Component\Process\Process->wait(NULL)
#1 /var/www/l4site/vendor/laravel/framework/src/Illuminate/Queue/Listener.php(63): Symfony\Component\Process\Process->run()
#2 /var/www/l4site/vendor/laravel/framework/src/Illuminate/Queue/Listener.php(50): Illuminate\Queue\Listener->runProcess(Object(Symfony\Component\Process\Process), 128)
#3 /var/www/l4site/vendor/laravel/framework/src/Illuminate/Queue/Console/ListenCommand.php(69): Illuminate\Queue\Listener->listen(NULL, 'default', 0, 128, 60)
#4 /var/www/l4site/vendor/laravel/framework/src/Illuminate/Console/Command.php(108): Illuminate\Queue\Console\ListenCommand->fire()
#5 /var/www/l4site/vendor/symfony/console/Symfony/Component/Console/Command/Command.php(240): Illuminate\Console\Command->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#6 /var/www/l4site/vendor/laravel/framework/src/Illuminate/Console/Command.php(96): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#7 /var/www/l4site/vendor/symfony/console/Symfony/Component/Console/Application.php(193): Illuminate\Console\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#8 /var/www/l4site/vendor/symfony/console/Symfony/Component/Console/Application.php(106): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#9 /var/www/l4site/artisan(59): Symfony\Component\Console\Application->run()
#10 {main}

enter image description here

Is this a bug? I don’t think the listener is supposed to time out!


Update

A second run of the listener timed out after 3 hours. I’m running Laravel 4 on nginx with php-fgm.

How to&Answers:

Regardless of how long you have it set to it will eventually run out of memory or timeout. You can use supervisor to keep it running. It is really simple to use.

First Install it:

sudo apt-get install supervisor

or use a method listed on their site like easy_install http://supervisord.org/installing.html

Now add a config file for supervisor. Open /etc/supervisor/conf.d/queue.conf (or whatever you want to name the file but put it in /etc/supervisor/conf.d/) and add:

[program:queue]
command=php artisan queue:listen
directory=/var/www/laravel
stdout_logfile=/var/www/laravel/app/storage/logs/supervisor_queue_listener.log
redirect_stderr=true

Explanation of the above: program:_____ is how we name what is run. We will reference that later. command is the command you want to run. directory is where it should be run. In my case I am in a project called “laravel”. stdout_logfile is the file where you want to redirect he stdout that is received from the command. redirect_stderr is set to true to direct all of the errors to the same log specified at stdout_logfile you can also set these to go to their own log file.

Open supervisor controller:

sudo supervisorctl

Read the contents of the /etc/supervisor/conf.d/ directory: (while still in supervisorctrl)

reread

Add the queue program to supervisor:

add queue

That’s it. Now it should be running. If you have erros look in your log file to see what is wrong.

Once you restart your server you will have to start supervisor again with sudo service supervisor start.

Laracasts covers Supervisor really well. If you aren’t subscribed to Laracasts I highly recommend it.

Answer:

queue:listen in Laravel 4 has a --timeout option. If you want an unlimited timeout you should set the –timeout option to 0.

./artisan queue:listen --timeout=0

Answer:

just run COMPOSER_PROCESS_TIMEOUT=4000 php artisan queue:listen

Answer:

Nor the process either the artisan is timing out. its the process wrapper.
Symfony\Component\Process\Process Class is used to run the whatever process (in my case Knp\Bundle\SnappyBundle\Snappy\LoggableGenerator the bundle that prints PDFs with wkhtmltoPDF is conidering that wkhtmltoPDF timed out just because I’m rendering a PDF with 11000 pages, it just needs more time)

Its nothing to do with php.ini’s max_execution_time = XXX (as its an exception thrown by Symfony Process instance with a confusing message)

You have to manage to get through the object relations to call

Symfony\Component\Process\Process->setTimeout(null) 

This solves de problem. In my case:

    $knp = $this->getContainer()->get('knp_snappy.pdf');
    /* @var $knp \Knp\Bundle\SnappyBundle\Snappy\LoggableGenerator */
    $knp->getInternalGenerator()->setTimeout(null);
    $pdf = $knp->getOutputFromHtml($this->view, $printOptions);

Answer:

The problem is there is a time limit.
Change the time limit and problem solved.
set_time_limit(howmanysecondsyouneed)
http://php.net/manual/en/function.set-time-limit.php

Answer:

I don’t think that the listener is timing out, I think that the process it’s trying to run is timing out. That exception comes from Symfony\Component\Process. Unfortunately the process code itself is a little over my head for today.

Answer:

The following command worked like a charm. It’s been running overnight now(more than 12hours).

php artisan queue:listen --timeout=0

Thanks to timgws answer.

Answer:

Have you considered using supervisord to ensure your process keeps on running. With supervisord installed in the event that your process dies for any reason, this daemon will start it back up again.The company I work for has been using it in conjunction with queue:listen for a while now.