PHP的max_execution_time不超时 [英] PHP max_execution_time not timing out

查看:327
本文介绍了PHP的max_execution_time不超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是不是如果睡眠才算超时或类似的东西常规问题之一。好吧,这里有一个问题:我已经设置PHP的的max_execution_time为15秒,理论上讲,该应超时当它跨过设定的限制,但它没有。阿帕奇已经换到php.ini文件和ini_get('的max_execution_time')之后已经重新启动是一切正常。有时脚本高达200秒这是疯狂的运行。我没有任何数据库的通信。所有的脚本并正在寻找在UNIX文件系统中的文件,并在某些情况下,重新定向到另一个JSP页面。没有睡眠()的脚本。

This is not one of the regular questions if sleep is counted for timeout or stuff like that. Ok, here's the problem: I've set the max_execution_time for PHP as 15 seconds and ideally this should time out when it crosses the set limit, but it doesn't. Apache has been restarted after the change to the php.ini file and an ini_get('max_execution_time') is all fine. Sometimes the script runs for upto 200 seconds which is crazy. I have no database communication whatsoever. All the script does is looking for files on the unix filesystem and in some cases re-directing to another JSP page. There is no sleep() on the script.

我计算出PHP脚本的总执行时间是这样的:

I calculate the total execution time of the PHP script like this:

在我设定的脚本的启动:

At the start of the script I set :

$_mtime = microtime();  
$_mtime = explode(" ",$_mtime);
$_mtime = $_mtime[1] + $_mtime[0]; 
$_gStartTime = $_mtime;

和结束时间($ _ gEndTime)被类似地计算。

总时间在我已经注册了一个关断功能计算:

and the end time($_gEndTime) is calculated similarly.
The total time is calculated in a shutdown function that I've registered:

register_shutdown_function('shutdown');
.............
function shutdown()
{
   ..............
   ..............
   $_total_time = $_gEndTime - $_gStartTime;
   ..............
   switch (connection_status ())
    {
    case CONNECTION_NORMAL:
      ....
      break;
      ....
    case CONNECTION_TIMEOUT:
      ....
      break;
      ......
    }
} 

注意:我无法使用$ _ SERVER ['REQUEST_TIME'],因为我的PHP版本不兼容。这很烂 - 我知道

Note: I cannot use $_SERVER['REQUEST_TIME'] because my PHP version is incompatible. That sucks - I know.

1)好了,我的第一个问题显然是为什么我的PHP脚本,甚至后的设定超时限制执行?

2)Apache在超时指令,它是300秒,但PHP二进制文件不能读取Apache的配置,这不应该是一个问题。

3)是否有一种可能性,即一些发送PHP进入睡眠模式?

4)我是不是计算错误的方式执行时间?有没有更好的方式来做到这一点?

1) Well, my first question obviously is is why is my PHP script executing even after the set timeout limit?
2) Apache has the Timeout directive which is 300 seconds but the PHP binary does not read the Apache config and this should not be a problem.
3) Is there a possibility that something is sending PHP into a sleep mode?
4) Am I calculating the execution time in a wrong way? Is there a better way to do this?


我在这一点上难住了。 PHP奇才 - 请帮助。


I'm stumped at this point. PHP Wizards - please help.

编辑:
我刚刚发现流操作是不是有一些日志的原因。即使存在不进行流式操作的延迟在脚本中只是随机。上下文切换可能只是原因。但我仍然没有一个明确的答案。我抬头一看<一个href=\"http://stackoverflow.com/questions/10025902/real-max-execution-time-for-php-on-linux?rq=1\">Real对于max_execution_time仅仅PHP在Linux上但是我不知道我想尝试了这一点。任何其他建议?

I just found out that the stream operations are not the cause with a few logs. The delay is just random within the script even when there are no streaming operations performed. Context switching may just be the reason. But I still dont have a clear answer. I looked up Real max_execution_time for PHP on linux but Im not sure I want to try that out. Any other suggestions?

推荐答案

的max_execution_time 唯一的限制剧本的执行时间本身 - CPU时间你的脚本。如果操作系统上下文切换到另一进程和花费一些时间在那里,它不会被同时计算。所以测量真实世界的时间和期望超时30秒后是不会是真实的任何给定的时间。当然,它忽略任何系统 EXEC 或网络时间以及

max_execution_time only limits script execution time itself - cpu time of your script. if the OS context switched to another process and spent some time there, it will not be counted as well. So measuring the real-world time and expecting a timeout after 30 seconds is not going to be true any given time. And of course, it disregards any system, exec or network times as well

这篇关于PHP的max_execution_time不超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆