laravel 如何增加laravel控制器方法的执行时间?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/37509479/
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 increase laravel controller method execution time?
提问by Bilal Hussain
I want to increase execution time of my controller method to 5 minutes . I searched but many times I found just one working idea that is increase the execution time in php.ini file but I do not want this I want to increase the execution time in laravel controller for one method only. Can any one tell me how I do that??? I tried many code one example is given below
我想将我的控制器方法的执行时间增加到 5 分钟。我搜索了很多次,但我发现只有一个可行的想法是增加 php.ini 文件中的执行时间,但我不想要这个,我只想增加 laravel 控制器中一种方法的执行时间。谁能告诉我怎么做???我尝试了很多代码,下面给出一个例子
public function postGetEvents1(){
set_time_limit(600);
//other code
}
}
回答by Alexey Mezenin
This should work for you, if you want to set higher execution time limit for just one method:
如果您只想为一种方法设置更高的执行时间限制,这应该适合您:
public function postGetEvents1(){
// Get default limit
$normalTimeLimit = ini_get('max_execution_time');
// Set new limit
ini_set('max_execution_time', 600);
//other code
// Restore default limit
ini_set('max_execution_time', $normalTimeLimit);
return;
}