PHP: don’t use time() or microtime() to measure execution time

As Thomas Habets posted on it’s blog ( gettimeofday() and time() should only be used to get the current time if the current wall-clock time is actually what you want. They should never be used to measure time or schedule an event X time into the future.

And because the time() and microtime() function relies on gettimeofday(), those functions don’t provide a reliable way to measure script execution time. The main issue comes from the fact that changing the server date/time directly affects the return value of these functions. As many servers rely on an NTP server to automatically adjust their time, the developers can be easily miss-leaded by some incorrect calculations due to automatically time adjustments.

Leave a Reply

Your email address will not be published. Required fields are marked *