PHP max_execution_time not timing out

Posted by Joey Ezekiel on Stack Overflow See other posts from Stack Overflow or by Joey Ezekiel
Published on 2012-06-29T09:10:56Z Indexed on 2012/06/29 9:15 UTC
Read the original article Hit count: 312

Filed under:
|

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.

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;

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;
      ......
    }
} 

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

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?


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

© Stack Overflow or respective owner

Related posts about php

Related posts about apache