简体   繁体   English

PHP max_execution_time的确切含义

[英]Exact meaning of PHP max_execution_time

The phrase "maximum execution time" is ambiguous: it could mean (a) the elapsed time since the script started, or (b) the total cputime taken by the script (including or excluding the cputime taken by operating system calls). 短语“最大执行时间”是模棱两可的:它可能表示(a)自脚本启动以来经过的时间,或(b)脚本占用的总cputime(包括或不包括操作系统调用占用的cputime)。

The very interesting post by kuba here Real max_execution_time for PHP on linux , finds that this depends upon whether PHP is running on Unix or Windows. kuba的一个非常有趣的帖子,这里是Linux上PHP的Real max_execution_time ,发现这取决于PHP是在Unix还是Windows上运行。 In essence he finds that on Unix it is (b) and on Windows or Cygwin it is (a). 本质上,他发现在Unix上为(b),在Windows或Cygwin上为(a)。

But, my server is Linux 2.6.32-358.18.1.el6.x86_64 #1 SMP x86_64 x86_64 x86_64 GNU/Linux, and I have a cron job that gets zapped after exactly 30 seconds elapsed time, despite its cpu time being less than 16 seconds: 但是,我的服务器是Linux 2.6.32-358.18.1.el6.x86_64#1 SMP x86_64 x86_64 x86_64 GNU / Linux,我的cron作业在经过30秒的时间后就会发生变化,尽管它的cpu时间小于16秒:

[Tuesday, 10-Dec-2013 10:22:33 GMT] Begin, cputime=0 secs.
[Tuesday, 10-Dec-2013 10:22:58 GMT] starting zip_close, cputime=10.12946 secs.
[10-Dec-2013 10:23:03 UTC] PHP Fatal error:  Maximum execution time of 30 seconds exceeded in xxx.php on line 149

This contradicts kuba's finding. 这与库巴的发现相矛盾。 Mine is PHP 5.3.26 and IU'm measuring cpu time with: 我的是PHP 5.3.26,IU用以下方法测量CPU时间:

function cputime() {
    $data = getrusage();
    return $data['ru_utime.tv_sec'] + $data['ru_utime.tv_usec'] / 1000000;

Can anyone clarify further? 谁能进一步澄清?

This depends entirely on your script. 这完全取决于您的脚本。 getrusage is not a reliable way to measure it. getrusage不是衡量它的可靠方法。 You're confused between 3 measurement methods, not 2: 您对3种测量方法感到困惑,而不是2:

  1. The absolute time since the startup of the script 自脚本启动以来的绝对时间
  2. The runtime of the script, so 1. minus system calls 脚本的运行时,因此1.减去系统调用
  3. Actual time the CPU is busy, so 2. minus other idle times because of wait states and the like CPU的实际时间,因此2.减去其他空闲时间(由于等待状态等)

getrusage measures 3, and is not what is documented. getrusage措施3,并且没有记录。 As such you're seeing the conflicting results - apparently your script has 14 seconds of general wait states and other inactive periods, without actually yielding completely like you would with system or streaming operations. 因此,您看到的是相互矛盾的结果-显然,您的脚本具有14秒的常规等待状态和其他不活动时间, 实际上并没有system或流式操作那样完全产生收益。

As the PHP docs state Windows uses method 1, and *nix systems use method 2. Nobody uses 3 because it doesn't really make sense as a timeout - it would mean timeouts become extremely aggressively tighter when system load is high and wait states rise. 正如PHP文档所述,Windows使用方法1,而* nix系统使用方法2。没有人使用3,因为它实际上没有意义上的超时时间-这意味着当系统负载很高且等待状态上升时,超时变得异常严格。

have a look at the documentation: 看一下文档:

http://www.php.net/manual/en/info.configuration.php#ini.max-execution-time http://www.php.net/manual/zh/info.configuration.php#ini.max-execution-time

how the programmers decided to implement the requirement it's obviously another story:) that's one of that cases in which the underlying OS matters a lot. 程序员如何决定实施该要求显然是另一回事了:)这是底层操作系统非常重要的情况之一。 The available APIs about cpu time on the particular OS will clearly shed some light on the problem. 特定操作系统上有关cpu时间的可用API显然可以使您对该问题有所了解。

this high-level requirement (the script running time) it's ambiguous and can be interpreted by the OS in many different ways. 这种高层次的要求(脚本运行时间)是模棱两可的,并且可由操作系统以多种不同的方式来解释。 The proof is the different timings you get. 证明是您获得不同的时机。

so there are many "right answers", exactly one per OS... 因此有很多“正确答案”,每个操作系统恰好一个...

AFAIK it is dependant on the OS. AFAIK它取决于操作系统。 Depending on the OS, the time taken to execute a shell exec or query for example will (eg windows) or wont (eg linux) be included in the take for max_execution_time. 根据操作系统的不同,执行shell exec或查询所需的时间将包含在max_execution_time的时间中(例如,windows)或将不会(例如,linux)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM