Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/162148-php-time-function-woes/
Share on other sites

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?

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

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');

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.

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?

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?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.