laravel 如何增加laravel的最大执行时间?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/53825881/
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 maximum execution time in laravel?
提问by Nadeshiko Rin
I want to upload large excel file. But because the file contains many rows, the loading is so slow and I got this error:
我想上传大的excel文件。但是因为文件包含很多行,加载速度很慢,我收到了这个错误:
FatalErrorException in Controller.php line 457: Maximum execution time of 120 seconds exceeded
Controller.php 第 457 行中的 FatalErrorException:超过了 120 秒的最大执行时间
I already put this on my .htaccess:
我已经把它放在我的 .htaccess 上:
<IfModule mod_php5.c>
php_value max_execution_time 1500
php_value upload_max_filesize 15M
</IfModule>
I also add this at the top of the controller:
我还在控制器的顶部添加了这个:
ini_set('memory_limit', '3000M');
ini_set('max_execution_time', '0');
I also change max_execution_time at the php.ini:
我还在 php.ini 中更改了 max_execution_time:
max_execution_time = 300
And also add this on config.inc.php:
并在 config.inc.php 上添加:
$cfg['ExecTimeLimit'] = 0;
I wonder why it's not work at all and keep getting me into that error... Is there a miss at the code? Any help would be appreciate, Thanks!
我想知道为什么它根本不起作用并不断让我陷入那个错误......代码有没有遗漏?任何帮助将不胜感激,谢谢!
回答by Mayur Panchal
Edit php.ini:
编辑php.ini:
php.inipath : /etc/php5(your php version)/apache2/php.ini
php.ini路径:/etc/php5(your php version)/apache2/php.ini
max_execution_time = 360 ; Maximum execution time of each script, in seconds (I CHANGED THIS VALUE)
max_input_time = 120 ; Maximum amount of time each script may spend parsing request data
memory_limit = 128M ; Maximum amount of memory a script may consume (128MB by default)
I hope this could help you.
我希望这可以帮助你。
回答by Kapitan Teemo
try to add this in your controller before the query
尝试在查询之前将其添加到您的控制器中
set_time_limit(300);
set_time_limit(300);
回答by jafar690
To temporarily set the limit, You can just do this in the code
要临时设置限制,您可以在代码中执行此操作
ini_set('max_execution_time', 300); //300 seconds = 5 minutes
or
或者
set_time_limit(300);
To change permanently, change the following values in php.ini
要永久更改,请更改以下值 php.ini
max_execution_time = 360 ; Maximum execution time of each script, in seconds (I CHANGED THIS VALUE)
max_input_time = 120 ; Maximum amount of time each script may spend parsing request data
memory_limit = 128M ; Maximum amount of memory a script may consume (128MB by default)