At first I want to point out, that this is not the same question as the others out there, because I don't want to increase the maximum execution time.
But to my problem: I have a long poll, so an AJAX-POST with timeout (higher than the maximum execution time of the PHP, so I don't have to worry about this value). I now recognized that if I leave my computer with opened browser (and running xampp), the POST won't be interrupted (like on reloading the page). When I get back to the computer (Windows, it went into sleep-mode), the script won't stop with my timer...:
$loop = array(
"count" => 0,
"sleeptime" => 2,
"maxec" => 30,
"start" => time(),
);
$change = false;
while ($change) {
$loop["count"]++;
$looptime = ((time() - $loop["start"]) / $loop["count"]);
if ($looptime * ($loop["count"] + 1) >= $loop["maxec"] - $looptime) {
$response["s"] = 1; // $response is an array which will be printed at the end / JSON format
$change = true;
} else {
sleep($loop["sleeptime"]);
}
// check my database
// if there is an update, set $change = true and print the update
}
... but gives me the standard-error-message:
Fatal error: Maximum execution time of 30 seconds exceeded in *file*.php on line 20
And my timer works at every* other situation... (* so far I'm able to say "every" ;) )
So I'm searching for a better way to print my response, e.g. {"response":1}, instead of the error-message. So I need a better working timer or a complete other solution.
I found this via google:
http://www.php.net/manual/en/function.register-shutdown-function.php
But I can't imagine how this could help me getting "before" the fatal error.