我运行了 php artisan queue:listen
,大约 27 分钟后,它停止处理更多作业。在我的错误日志中,我看到错误:
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}
这是一个错误吗?我认为听众不应该超时!
更新
监听器的第二次运行在 3 小时后超时。我正在使用 php-fgm 在 nginx 上运行 Laravel 4。
最佳答案
不管你设置多久,它最终都会耗尽内存或超时。您可以使用 supervisor 来保持它的运行。使用起来非常简单。
首先安装它:
sudo apt-get install supervisor
或使用他们网站上列出的方法,例如 easy_install http://supervisord.org/installing.html
现在为主管添加一个配置文件。打开/etc/supervisor/conf.d/queue.conf
(或者任何你想命名的文件,但把它放在/etc/supervisor/conf.d/
)并添加:
[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
上面的解释:program:_____
是我们如何命名运行的。我们稍后会引用它。 command
是您要运行的命令。 directory
是它应该运行的地方。就我而言,我在一个名为“laravel”的项目中。 stdout_logfile
是您要重定向从命令接收的标准输出的文件。 redirect_stderr
设置为 true 以将所有错误定向到 stdout_logfile
中指定的同一日志,您也可以将它们设置为转到它们自己的日志文件。
打开主管 Controller :
sudo supervisorctl
读取/etc/supervisor/conf.d/
目录的内容:(同时还在supervisorctrl中)
reread
将队列程序添加到supervisor:
add queue
就是这样。现在它应该正在运行。如果您有错误,请查看您的日志文件以了解问题所在。
一旦你重新启动你的服务器,你将不得不使用 sudo service supervisor start
再次启动 supervisor。
Laracasts covers Supervisor真的很好。如果您没有订阅 Laracasts,我强烈推荐它。
关于php - Laravel 4 队列 :listen times out,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15891852/