7

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.

Wouter J
  • 41,455
  • 15
  • 107
  • 112
Nyxynyx
  • 61,411
  • 155
  • 482
  • 830
  • When was the last time you ran `composer update`? It might have been fixed since you last tried. – Phill Sparks Apr 12 '13 at 16:21
  • @PhillSparks I just did a `composer update` and the problem persists. The function called by the worker does a `shell_exec()`. Another listener's worker that does not call `shell_exec()` does not have this timeout problem. Wonder if its due to `shell_exec()`... – Nyxynyx Apr 12 '13 at 17:06

8 Answers8

9

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.

DutGRIFF
  • 5,103
  • 1
  • 33
  • 42
  • 1
    This is the best answer. Setting --timeout=0 is a bad idea. Jobs should timeout or be broken into chunks for processing so each job can be handled in a small amount of time. Use supervisor to make sure your jobs are always running and then handle the timeout exceptions as they come so you know where you need to optimize your jobs. – phirschybar Jan 02 '15 at 14:59
7

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
Tim Groeneveld
  • 8,739
  • 3
  • 44
  • 60
3

just run COMPOSER_PROCESS_TIMEOUT=4000 php artisan queue:listen

sedigo
  • 125
  • 2
  • 11
1

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);
juanmf
  • 2,002
  • 2
  • 26
  • 28
0

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

  • I restarted the queue listener and now it's been running fine for over an hour... shouldn't Laravel remove the time limit by itself since this is supposed to be a queue listener with a `while(true)` infinite loop? – Nyxynyx Apr 09 '13 at 04:07
  • I'm not familiar with Laravel, but as you see that solved your time limit problem, because by default there is a time limit –  Apr 09 '13 at 15:09
0

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.

Phill Sparks
  • 20,000
  • 3
  • 33
  • 46
  • Setting `set_time_limit(0)` in the function the worker calls does not prevent the error... wonder what's causing it – Nyxynyx Apr 12 '13 at 16:17
0

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.

Xolani
  • 1,308
  • 1
  • 9
  • 10
0

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.

Paul Blakey
  • 667
  • 10
  • 13