[英]How to exceed max_execution_time in PHP
In PHP, I want to run a script who need 2 minutes to compute but my max_execution_time is only 30 seconds. 在PHP中,我想运行一个需要2分钟来计算的脚本,但是我的max_execution_time只有30秒。
I can't change my max_execution_time in php.ini nor call shell_exec 我无法在php.ini中更改max_execution_time,也无法调用shell_exec
I already done all the optimization I could think of. 我已经做了所有我能想到的优化。 Any idea? 任何想法?
Even if you can't change the php.ini
file itself, you might be able to change options via PHP code with ini_set
. 即使您无法更改php.ini
文件本身,也可以通过ini_set
通过PHP代码更改选项。
You can also try to call set_time_limit
inside your code, resetting the current time counter (this doesn't work in safe mode). 您也可以尝试在代码内调用set_time_limit
,以重置当前时间计数器(在安全模式下不起作用)。
If that doesn't work, try to split the task up into multiple sub-tasks and save the temporary results, so that you can perform the task on multiple executions and thus bypass the time limit. 如果这不起作用,请尝试将任务拆分为多个子任务并保存临时结果,以便您可以多次执行任务,从而绕过时间限制。
The "best" option you have is to cut your algorithm into smaller part. 您拥有的“最佳”选项是将算法分成较小的部分。 Each part should execute within 30 second to avoid timeout. 每个部分应在30秒内执行以避免超时。 Here are few ideas. 这里有一些想法。
Using CURL: 使用CURL:
Using CRON task: 使用CRON任务:
You can also set it in your .htaccess file 您也可以在.htaccess文件中进行设置
Add the following line to your .htaccess file 将以下行添加到您的.htaccess文件中
php_value max_execution_time 200
使用方式
ini_set('max_execution_time', 100);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.