set_time_limit(0) 和“最大执行时间”PHP
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8377137/
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
set_time_limit(0) and "Maximum execution time" PHP
提问by Darren Sweeney
I have a script where I have set:
我有一个脚本,我已经设置:
set_time_limit(0)
but still get
但仍然得到
Fatal error: Maximum execution time of 90 seconds exceeded in /home/Feed.php on line 234
I've also tried setting:
我也试过设置:
php_value max_execution_time 120
in the .htaccess file but still can't stop this error - any ideas why this is not overriding?
在 .htaccess 文件中,但仍然无法阻止此错误 - 为什么这不是覆盖的任何想法?
采纳答案by Spudley
Most likely, your host is running a copy of PHP with the Suhoshin patch installed. This patch provides a large number of security and operational enhancements to PHP, including allowing the host to disable functions like set_time_limit()
.
最有可能的是,您的主机正在运行安装了 Suhoshin 补丁的 PHP 副本。此补丁为 PHP 提供了大量安全性和操作增强功能,包括允许主机禁用set_time_limit()
.
There are other ways a host could disable the set_time_limit()
function, but that's the most likely. (especially as you've already ruled out Safe Mode)
主机可以通过其他方式禁用该set_time_limit()
功能,但这是最有可能的。(特别是因为您已经排除了安全模式)
Why would they disable this function? Because a PHP function that takes a long time to run also typically takes a lot of server resources; in a shared hosting environment, it is wise for the host to mitigate this kind of thing to avoid having a rogue script impact other users.
他们为什么要禁用这个功能?因为一个需要很长时间运行的 PHP 函数通常也会占用大量的服务器资源;在共享主机环境中,主机减轻这种事情以避免流氓脚本影响其他用户是明智的。
What can you do about it?
你能为这个做什么?
Firstly, are you sure you need to set the time limit? Do you know why your script takes that much time to run? Can you work around it? Perhaps doing a bit of profiling on your code might help you find the bottlenecks and speed up the program.
首先,您确定需要设置时间限制吗?你知道为什么你的脚本需要这么多时间来运行吗?你能解决它吗?也许对您的代码进行一些分析可能会帮助您找到瓶颈并加速程序。
Alternatively, if you really do need to set the time limit, you may need to ask your host to enable you to do so, or else upgrade your package or switch hosting providers.
或者,如果您确实需要设置时间限制,您可能需要让您的主机允许您这样做,或者升级您的软件包或切换托管服务提供商。
回答by virushuo
This function has no effect when PHP is running in safe mode. There is no workaround other than turning off safe mode or changing the time limit in the php.ini
当 PHP 在安全模式下运行时,此功能无效。除了关闭安全模式或更改 php.ini 中的时间限制外,没有其他解决方法
回答by ReadWriteCode
If you are sure it isn't running in safe mode...
如果您确定它不是在安全模式下运行...
http://php.net/manual/en/function.set-time-limit.php
http://php.net/manual/en/function.set-time-limit.php
"When called, set_time_limit()
restarts the timeout counter from zero."
“调用时,set_time_limit()
从零重新启动超时计数器。”
So you could, theoretically, call set_time_limit(0)
repeatedly.
所以理论上你可以call set_time_limit(0)
重复。
However, it is possible for your hosting provider to prevent that via safe mode, etc.
但是,您的托管服务提供商可以通过安全模式等来阻止这种情况。
Honestly, I'd just try to get a cheap VPS where you control things if you need to customize that sort of thing.
老实说,如果您需要自定义那种东西,我只是尝试获得一个便宜的 VPS,您可以在其中控制事物。