Laravel 4 队列:监听超时

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15891852/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 07:41:29  来源:igfitidea点击:

Laravel 4 Queue:listen times out

phplaravellaravel-4symfony-components

提问by Nyxynyx

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

我跑了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}

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.

监听器的第二次运行在 3 小时后超时。我正在使用 php-fgm 在 nginx 上运行 Laravel 4。

回答by DutGRIFF

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.

无论您将其设置多久,最终都会耗尽内存或超时。您可以使用 supervisor 来保持它运行。使用起来真的很简单。

First Installit:

首先安装它:

sudo apt-get install supervisor

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

或者使用他们网站上列出的方法,比如 easy_install http://supervisord.org/installing.html

Now add a config filefor 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:

现在为主管添加一个配置文件。打开/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

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

上面的解释:program:_____是我们如何命名运行的东西。我们稍后会参考。command是您要运行的命令。directory是它应该运行的地方。就我而言,我在一个名为“laravel”的项目中。stdout_logfile是您要重定向从命令接收到的标准输出的文件。redirect_stderr设置为 true 以将所有错误定向到指定的同一日志,stdout_logfile您也可以将这些设置为转到它们自己的日志文件。

Open supervisor controller:

打开主管控制器

sudo supervisorctl

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

读取目录内容/etc/supervisor/conf.d/:(还在supervisorctrl中)

reread

Add the queue program to supervisor:

将队列程序添加到 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.

重新启动服务器后,您将不得不再次使用sudo service supervisor start.

Laracasts covers Supervisorreally well. If you aren't subscribed to Laracasts I highly recommend it.

Laracasts 很好地涵盖了 Supervisor。如果你没有订阅 Laracasts,我强烈推荐它。

回答by Tim Groeneveld

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

queue:listen在 Laravel 4 中有一个--timeout选项。如果您想要无限超时,您应该将 --timeout 选项设置为 0。

./artisan queue:listen --timeout=0

回答by sedigo

just run COMPOSER_PROCESS_TIMEOUT=4000 php artisan queue:listen

只需运行 COMPOSER_PROCESS_TIMEOUT=4000 php artisan queue:listen

回答by juanmf

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)

工匠的过程也没有超时。它的过程包装器。Symfony\Component\Process\Process 类用于运行任何进程(在我的情况下 Knp\Bundle\SnappyBundle\Snappy\LoggableGenerator 使用 wkhtmltoPDF 打印 PDF 的包正在考虑 wkhtmltoPDF 超时只是因为我正在渲染一个 PDF 11000页,只是需要更多时间)

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)

它与 php.ini 的 max_execution_time = XXX 无关(因为它是由 Symfony Process 实例抛出的一个带有混淆消息的异常)

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:

这解决了de问题。就我而言:

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

回答by juanmf

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

问题是有时间限制。
更改时间限制并解决问题。
set_time_limit(howmanysecondsyouneed)
http://php.net/manual/en/function.set-time-limit.php

回答by Phill Sparks

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.

我不认为侦听器超时,我认为它试图运行的进程超时。该异常来自Symfony\Component\Process。不幸的是,今天的流程代码本身让我有点不知所措。

回答by Xolani

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

下面的命令就像一个魅力。它现在已经运行了一夜(超过 12 小时)。

php artisan queue:listen --timeout=0

Thanks to timgws answer.

感谢 timgws 的回答。

回答by Paul Blakey

Have you considered using supervisordto 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.

您是否考虑过使用supervisord来确保您的进程继续运行。如果您的进程因任何原因终止,安装 supervisord 后,该守护程序将再次启动它。我工作的公司一直在将它与 queue:listen 结合使用一段时间。