tthomas Posted June 14, 2009 Share Posted June 14, 2009 We are using the php time() function to time stamp entries on our web site. 3 times in the last year, the time function has either been off by about 1/2 hour, or reports 0 altogether. We are running on eApps on a VM managed by Parallels. Is it possible for the php time function to incorrectly report the server time? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/162148-php-time-function-woes/ Share on other sites More sharing options...
corbin Posted June 14, 2009 Share Posted June 14, 2009 Unless you have a fault PHP binary, or your OS's kernel has issues, I don't think that should ever happen x.x. (I've never looked at the C code behind PHP's time() function though.) Are you absolutely sure it's time() returning 0 and something else isn't changing a stored value to 0 later? Also, what version of PHP? Quote Link to comment https://forums.phpfreaks.com/topic/162148-php-time-function-woes/#findComment-855672 Share on other sites More sharing options...
tthomas Posted June 15, 2009 Author Share Posted June 15, 2009 Here's the code that processes the timestamp (actually my call is to date() and the call to time() is by default): function myDate($timeStamp=false) { return (($timeStamp) ? date("Y-m-d H:i:s", $timeStamp) : date("Y-m-d H:i:s")); } The assignment of the date happens here (So far there are no calls in the code that actially pass $timestamp): $m->dateEntered = myDate(); I am using PHP version 5.2.5 Quote Link to comment https://forums.phpfreaks.com/topic/162148-php-time-function-woes/#findComment-855936 Share on other sites More sharing options...
rhodesa Posted June 15, 2009 Share Posted June 15, 2009 It could be that your system time is off. PHP is pulling the current timestamp from the system, and if the NTP daemon is not configured, it can slowly get out of sync with the atomic clock. What is the out of the following, and is the output the correct time for your timezone?: echo date('r'); Quote Link to comment https://forums.phpfreaks.com/topic/162148-php-time-function-woes/#findComment-855970 Share on other sites More sharing options...
tthomas Posted June 16, 2009 Author Share Posted June 16, 2009 Right now (4:28 PM EST) it reads The date is Tue, 16 Jun 2009 16:27:50 -0400 => 0 Quote Link to comment https://forums.phpfreaks.com/topic/162148-php-time-function-woes/#findComment-857443 Share on other sites More sharing options...
ldougherty Posted June 16, 2009 Share Posted June 16, 2009 The fact that the time is good now does not mean the time was good when your script executed previously. A lot of Linux servers run cron scripts to keep the date/time up to date. It is most likely that your server time was off when the script ran but there is no way to know for sure. Quote Link to comment https://forums.phpfreaks.com/topic/162148-php-time-function-woes/#findComment-857447 Share on other sites More sharing options...
tthomas Posted June 16, 2009 Author Share Posted June 16, 2009 That was my guess, but the hosting provider doesn't agree :-\ This has not been a problem, but all of the sudden has been an issue 3 times in the last few days. The time jumps into the future, then reports zeros, then goes back to normal. Quote Link to comment https://forums.phpfreaks.com/topic/162148-php-time-function-woes/#findComment-857477 Share on other sites More sharing options...
tthomas Posted June 19, 2009 Author Share Posted June 19, 2009 This issue is still recurring a couple of times a day. I decided to set a timestamp column in MySQL and capture MySQL's account of the time. Since I have done this, there was one instance where it happened again, and interestingly, the timestamp from Mysql is accurate wereas the time passed from PHP is not: the first bad record is ~ 4.75 hrs behind, then the next record (posted 12 minutes later) the php time is '0000-00-00 00:00:00'. This is a recurring pattern... everything is fine, then there are 1 or more times that are either slow or fast by several hours even though the time between posts is 10s of minutes to hours, then there is one or more '0000-00-00 00:00:00' posts, then it fine again. Now that is starts to look like a pattern, here's a twist: For the first time ever, a record posted with a value of 0 for the user-id. Thoughts? Quote Link to comment https://forums.phpfreaks.com/topic/162148-php-time-function-woes/#findComment-859326 Share on other sites More sharing options...
tthomas Posted June 19, 2009 Author Share Posted June 19, 2009 Here's an interesting observation about some of the time discrepancies: in the date being passed from php, the time is getting shifted. For example, the MySQL timestamp 2009-06-19 13:05:05 is being stored as 2009-06-19 05:05:00 when passed from php. Any thoughts? Quote Link to comment https://forums.phpfreaks.com/topic/162148-php-time-function-woes/#findComment-859800 Share on other sites More sharing options...
corbin Posted June 19, 2009 Share Posted June 19, 2009 Do MySQL and PHP have the same timezone? Quote Link to comment https://forums.phpfreaks.com/topic/162148-php-time-function-woes/#findComment-859821 Share on other sites More sharing options...
tthomas Posted June 23, 2009 Author Share Posted June 23, 2009 Yes. The vast majority of times the php and MySQL date/time is exact, but when they are off, they are either off by this shift in the time part, or the php date/time is just 0. Thoughts? Quote Link to comment https://forums.phpfreaks.com/topic/162148-php-time-function-woes/#findComment-862236 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.