Time Differences between PHP and MySQL

Here's an interesting observation I've just made while working on the NeoInvoice project… These are the results of running PHP's date() function on the current time, along with the result of running MySQL's SELECT NOW() function:

Windows Dev Server:

PHP Time  : 2010-06-13 14:24:58
MySQL Time: 2010-06-13 14:24:34

Linux Staging Server:

PHP Time  : 2010-06-13 14:24:58
MySQL Time: 2010-06-13 14:24:58

The differences between PHP/Apache's time and MySQL's time on Windows is an entire 24 seconds! This is consistent as well, after reloading the script several times, we still get the same 24 second different offset. Linux consistently has a zero second difference.

For the scholars out there, the Windows server is running APC, and the Linux server is running eAccelerator. Here's the script we used for timing (you'll want to replace the runQuery() function to reproduce):

<?php
require_once("config-mysql.php");
$result = runQuery("SELECT NOW() AS mysql_time");
$row = mysql_fetch_assoc($result);
$mysql_time = date("Y-m-d H:i:s", strtotime($row['mysql_time']));
$php_time = date("Y-m-d H:i:s");
?>
<pre>
PHP Time  : <?=$php_time?>
MySQL Time: <?=$mysql_time?>
</pre>
Thomas Hunter II Avatar

Thomas is the author of Advanced Microservices and is a prolific public speaker with a passion for reducing complex problems into simple language and diagrams. His career includes working at Fortune 50's in the Midwest, co-founding a successful startup, and everything in between.