PHP 执行时间超过 max_execution_time... 有时

标签 php apache curl timeout

我有一个 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 directive max_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 using system(), 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/

相关文章:

php - 如何比较两个数组的值?

javascript - 用于压缩类 DNA 字符串的简单紧凑代码

apache - 在 Windows 中启用 Apache 中的 mod_headers

php - .htaccess 拒绝所有,包括 htaccess 文件和显示 404 - 我该怎么做?

php - 某些网站的 cURL 超时,但在其他网站上运行良好

php - 在 Windows 8.1 上安装 Apache、PHP、MySQL - Apache 无法启动 - 请求的操作失败

php - php中有 "map"函数吗?

java - 监视器 tomcat 中禁用的启动和停止按钮

java - 在 Java 程序中执行命令行参数时出现问题

通过代理使用 FTP 的 RCurl getURL