5

I'm trying to figure out why PHP takes 1 full second to execute a register_shutdown_function. And if there is a way to overcome this.

<?php

$start_time = microtime(true);

function shutdown($start_time)
{
    $time_diff = round(1000 * (microtime(true)-$start_time));
    echo $time_diff . "ms<br/>";
}

register_shutdown_function('shutdown', $start_time);
register_shutdown_function('shutdown', $start_time);
register_shutdown_function('shutdown', $start_time);
register_shutdown_function('shutdown', $start_time);
register_shutdown_function('shutdown', $start_time);

Outputs:

1001ms
2001ms
3003ms
4003ms
5003ms

Running XAMPP 1.6.8 on Windows / PHP: 5.2.6

Eborbob
  • 1,905
  • 1
  • 15
  • 30
mfrancis107
  • 1,401
  • 1
  • 13
  • 21
  • 2
    Doesn't happen for me: I get five "0ms" on 5.3.15. What does an `strace` show you? – bishop Dec 08 '13 at 22:21
  • http://3v4l.org/ZGQ22 – hek2mgl Dec 08 '13 at 22:34
  • I'm running on with XAMPP 1.6.8 with Windows 7. Wondering if it's windows specific. – mfrancis107 Dec 08 '13 at 22:57
  • Could be. If you disable all the dll loading in php.ini, do you get expected performance? – bishop Dec 08 '13 at 23:06
  • 4
    Looks like Xdebug was causing it. Anyone else want to test it to see if turning on xdebug causes the delay? – mfrancis107 Dec 08 '13 at 23:54
  • 2
    XDebug tracing will do this: http://stackoverflow.com/questions/15035565/php-profiling-delay-before-shutdown-function – rich remer Dec 09 '13 at 07:55
  • There is a correct answer to your question http://stackoverflow.com/a/19273025/341260 – barbushin Jun 04 '15 at 09:24
  • 1
    @barbushin It might be worth putting that link in an answer so it can be marked as correct and the question can be closed. Or is marking as a duplicate more appropriate even though the question is totally different. – DanielM Jun 30 '15 at 13:34
  • Possible duplicate of [enabling xdebug remote debug makes apache server very slow](http://stackoverflow.com/questions/17736304/enabling-xdebug-remote-debug-makes-apache-server-very-slow) – A.L Apr 28 '16 at 12:14

0 Answers0