note 50300 added to function.microtime
| From: | php at washboardabs dot net | Date: | Thu, 24 Feb 2005 08:57:21 +0000 |
| Subject: | note 50300 added to function.microtime | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-85471@lists.php.net to get a copy of this message | ||
Interesting quirk (tested in PHP 5.0.3): You can get very wacky results from microtime when it is
called in the destructor of an object at the end of a script. These times vary enormously and can be
in the *past*, when compared to microtime calls in the body of the script.
As a case example, I played with a timer object that measured microtime when it was created at the
start of the script, and measured microtime again at the end of the script using __destruct(); and
then printed the total execution time (end time - start time) at the bottom of the page. On short
scripts, this would often give a negative time!
This quirk does not appear if microtime is measured with an automatic shutdown function (using
<?PHP register_shutdown_function('myfunc') ?>. Incidentally, the automatic shutdown
functions are called after output buffers are flushed but before object destructors are called.
----
Manual Page -- http://www.php.net/manual/en/function.microtime.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+50300
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+50300&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+50300&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+50300&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+50300&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+50300&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+50300&report=yes
Search -- http://master.php.net/manage/user-notes.php