简体   繁体   English

在PHP中设置最大执行时间

[英]Set maximum execution time in PHP

I tried to increase the max execution time in my php.ini file. 我试图增加php.ini文件中的最大执行时间。 It doesn't work, however. 但是,它不起作用。 Considering the fact that I' ve got a large file (containing 300 pages) I have to download using PHPEXCEL, I did the following in my php. ini 考虑到我必须使用PHPEXCEL下载一个大文件(包含300页)的事实,我在php. ini做了以下操作php. ini php. ini file: php. ini文件:

max_execution_time = 999999999     
max_input_time = 9999999    
max_input_nesting_level = 64  
memory_limit = 128M      

Is there anyone who knows what to do in this situation? 有谁知道在这种情况下该怎么办?

If you don't want a limit, then you can use this: 如果您不希望有限制,则可以使用以下方法:

set_time_limit(0);

But only if safe_mode is off, otherwise you can use ini_set: 但是只有在safe_mode关闭的情况下,否则您可以使用ini_set:

ini_set('max_execution_time', 300); // 300 Seconds

Thanks. 谢谢。

You can use 0 : 您可以使用0:

max_execution_time = 0     

That will disabled the limitation. 那将禁用限制。 Don't forget to restart apache after. 不要忘记之后重新启动apache。

You can also user the PHP version : 您也可以使用PHP版本:

<?php set_time_limit(0); ?>

On some of my php scripts that take long time to run I always use the following code at the top: 在一些需要很长时间才能运行的php脚本上,我总是在顶部使用以下代码:

set_time_limit(0);
ignore_user_abort(1);

Explanation: 说明:

set_time_limit(0);

We're telling php the script can run for unlimited time. 我们告诉php脚本可以无限期运行。

ignore_user_abort(1);

We're telling php to continue running the script even if the user disconnects. 我们告诉php即使用户断开连接也继续运行脚本。
ie: closing the browser or disconnect from a SSH session. 即:关闭浏览器或断开SSH会话的连接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM