如何为 Laravel 工匠设置超时
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29861777/
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
How to set timeout for Laravel artisan
提问by HymanYe
How to set timeout for an artisan job? And when time out the job will be killed.
如何为工匠工作设置超时?当超时工作将被杀死。
I'm using Laravel 5.0 on my application.I scheduled some artisan jobs every minute in app/Console/Kernel.php. When I grep those jobs
我在我的应用程序上使用 Laravel 5.0。我每分钟在 app/Console/Kernel.php 中安排一些工匠工作。当我 grep 那些工作
ps -ef | grep artisan
It seems that every job is running in separate process.
似乎每个作业都在单独的进程中运行。
root 23322 1 0 13:44 ? 00:00:00 xxx/php-5.5.7/bin/php artisan fetchTopic 0 10 1
root 23324 1 0 13:44 ? 00:00:00 xxx/php-5.5.7/bin/php artisan fetchTopic 0 10 2
root 23326 1 0 13:44 ? 00:00:00 xxx/php-5.5.7/bin/php artisan fetchComment
根 23322 1 0 13:44 ? 00:00:00 xxx/php-5.5.7/bin/php 工匠 fetchTopic 0 10 1
根 23324 1 0 13:44 ? 00:00:00 xxx/php-5.5.7/bin/php artisan fetchTopic 0 10 2
根 23326 1 0 13:44 ? 00:00:00 xxx/php-5.5.7/bin/php artisan fetchComment
And when one job finish its task, the process will be killed automatically. But it is strange that some of the processes are not killed normally. And over time, more and more strange processes are permanent which lead to CPU 100%. So I want to set an timeout for the artisan job, when time out the job will be killed automatically.
当一项工作完成其任务时,该进程将自动终止。但是奇怪的是,有些进程没有被正常杀死。随着时间的推移,越来越多的奇怪进程是永久性的,导致 CPU 100%。所以我想为工匠工作设置一个超时,当超时工作将被自动终止。
采纳答案by Margus Pala
I checked the Laravel code and there is no graceful way of killing these long artisan processes.
我检查了 Laravel 代码,没有优雅的方法可以杀死这些漫长的工匠进程。
However you can limit overall php execution time on your own risk. You can use function set_time_limit()for this or add max_execution_time in your php.ini
但是,您可以自行承担风险来限制 php 的整体执行时间。您可以为此使用函数set_time_limit()或在 php.ini 中添加 max_execution_time
回答by Attila Fulop
I had the same issue and changing the value of max_input_time
in the cliphp.ini file lead to the desired effect.
我有同样的问题,改变的值max_input_time
在CLIphp.ini文件导致预期的效果。
Example:(/etc/php/7.3/cli/php.ini
)
例子:( /etc/php/7.3/cli/php.ini
)
;;;;;;;;;;;;;;;;;;;
; Resource Limits ;
;;;;;;;;;;;;;;;;;;;
; Maximum execution time of each script, in seconds
; http://php.net/max-execution-time
; Note: This directive is hardcoded to 0 for the CLI SAPI
max_execution_time = 99