I'm experiencing timeouts when running a Job Queue listener (infinite while loop). The listener calls a worker whose function involves executing a software PhantomJS using shell_exec()
.
I'm running nginx 1.2.7 with php5-fpm and PHP framework Laravel 4 (which uses symfony components).
Problem: After running for awhile, the listener will quit with the error The process timed out
. I suspect it is due to the shell_exec()
that takes a very long time to return its results.
Attempts: I tried increasing the timeouts settings on nginx to 600 seconds but that did not help. set_time_limit(0)
does not help either.
How can you prevent it from timing out, or at least prevent the timing out error from killing the queue listener?
sites-enabled/mysite.com
server {
listen 80;
server_name www.mysite.com mysite.com *.mysite.com;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
root /var/www/mysite/public;
index index.php index.html;
location / {
try_files $uri $uri/ /index.php?$args ;
}
location ~ \.php$ {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_read_timeout 600;
fastcgi_send_timeout 600;
client_body_timeout 600;
send_timeout 600;
proxy_read_timeout 600;
}
}
Error stacktrace
exception 'Symfony\Component\Process\Exception\RuntimeException' with message 'The process timed out.' in /var/www/mysite/vendor/symfony/process/Symfony/Component/Process/Process.php:413
Stack trace:
#0 /var/www/mysite/vendor/symfony/process/Symfony/Component/Process/Process.php(201): Symfony\Component\Process\Process->wait(NULL)
#1 /var/www/mysite/vendor/laravel/framework/src/Illuminate/Queue/Listener.php(63): Symfony\Component\Process\Process->run()
#2 /var/www/mysite/vendor/laravel/framework/src/Illuminate/Queue/Listener.php(50): Illuminate\Queue\Listener->runProcess(Object(Symfony\Component\Process\Process), 128)
#3 /var/www/mysite/vendor/laravel/framework/src/Illuminate/Queue/Console/ListenCommand.php(69): Illuminate\Queue\Listener->listen(NULL, 'default', 0, 128, 60)
#4 /var/www/mysite/vendor/laravel/framework/src/Illuminate/Console/Command.php(108): Illuminate\Queue\Console\ListenCommand->fire()
#5 /var/www/mysite/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/mysite/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/mysite/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/mysite/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/mysite/artisan(59): Symfony\Component\Console\Application->run()
#10 {main}
Timeouts are still occuring when using Apache 2.2.22 and default settings. Any ideas what settings can be changed to avoid the timeouts?
Check #3. That function call has a very suspicious 60 as argument. Are you sure it's php limit you are hitting or is the code there listening for console output for max 60 seconds?
Once the listen
process takes up too much memory, it kills itself.
if ($this->memoryExceeded($memory))
{
$this->stop(); return;
}
I've heard you're supposed to use Supervisor to ensure the process is restarted and always running. I'm not sure why you have to do this though /: and haven't tried it myself yet.