我有一个 PHP 类,调用后将时间限制设置为 60 秒。这个类唯一的特别之处在于它使用了 curl_multi_exec()。
set_time_limit(60);
ini_set('max_execution_time', 60);
问题是在 Apache 的/server-status 页面下,这个页面和另一个使用单线程 curl 的页面有时会超过它们的 max_execution_time 并达到 200 秒!
我错过了什么?有没有办法设置 Apache 终止运行时间超过 90 秒的脚本(甚至连接)?
最佳答案
来自 the manual :
The
set_time_limit()
function and the configuration directivemax_execution_time
only affect the execution time of the script itself. Any time spent on activity that happens outside the execution of the script such as system calls usingsystem()
, stream operations, database queries, etc. is not included when determining the maximum time that the script has been running.
因为 curl 请求属于此类,所以等待请求完成所花费的时间将不计算在内。您应该将 curl 设置 CURLOPT_TIMEOUT
设置为较低的值,或者监控您自己执行脚本所花费的时间。
关于PHP 执行时间超过 max_execution_time... 有时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5678100/