Server Time Issues

Status
Not open for further replies.

time4crime

New Member
Messages
5
Reaction score
0
Points
0
Hey guys, I am having a rather big issue with my server time and I'd like to know what exactly is causing it, or how to fix it :biggrin:

I have already searched the forums to see if anyone else had similar problems but apparently they didn't.

What my problem is, is that if a user is online and had just clicked a link then it will say USERNAME Last Active -188 Seconds ago. Basically it should say 0 seconds ago yet it says negative 188. Also, when this first started, it said -150 seconds, but everyday it goes down one.

Any help would be greatly appreciated :biggrin:
Thanks.
 

descalzo

Grim Squeaker
Community Support
Messages
9,372
Reaction score
326
Points
83
time4crime said:
What my problem is, is that if a user is online and had just clicked a link then it will say USERNAME Last Active -188 Seconds ago. Basically it should say 0 seconds ago yet it says negative 188. Also, when this first started, it said -150 seconds, but everyday it goes down one.

What is it ? And how does it tell/record time?

Edit/Add:

If you are comparing a PHP time with a mySQL timestamp, that might be the problem.
 
Last edited:

time4crime

New Member
Messages
5
Reaction score
0
Points
0
"IT" is just text. It will say on a users online page something like this
USER1 - -188 secs ago
USER 2 - -182 secs ago
USER 3 - -178 secs ago

When It should say

USER1 - 0 secs ago
USER2 - 6 secs ago
USER3 - 10 secs ago

An example of the code that calls this is:

Code:
if($r['laston'] > 0)
{
$la=time()-$r['laston'];
$unit="seconds";
if($la >= 60)
{
$la=(int) ($la/60);
$unit="minutes";
}
if($la >= 60)
{
$la=(int) ($la/60);
$unit="hours";
if($la >= 24)
{
$la=(int) ($la/24);
$unit="days";
}
}
$str="$la $unit ago";
}
and then later it says
Code:
Last Action: $str<br />

But instead of being accurate, it is 188 seconds off.


Here is another place where this happens...

Just adding... This is what I was talking about at the top with the USER1, USER2, etc.
Code:
$q=mysql_query("SELECT COUNT(*) as cnt FROM users WHERE laston>unix_timestamp()-15*60 ORDER BY laston DESC",$c); 
while($r=mysql_fetch_array($q)) 
print "Users online in  the last 15 mins <font color=white>$r[cnt]</font><br>";
 
Last edited:

descalzo

Grim Squeaker
Community Support
Messages
9,372
Reaction score
326
Points
83
mySQL time is not the same as PHP time.
 

time4crime

New Member
Messages
5
Reaction score
0
Points
0
Alright thanks, do you know how I could fix this? I'm at a loss on this :happysad:
 

Livewire

Abuse Compliance Officer
Staff member
Messages
18,169
Reaction score
216
Points
63
Alright thanks, do you know how I could fix this? I'm at a loss on this :happysad:

There's a brutal fix but I'm not 100% sure -how- exactly to fix it in code.

The two ways I can think of are either to evaluate the current time in php -first- and then insert the returned value into mysql (this is probably the "correct" way to do it), OR when getting time via php, replace it with a query to the mysql server to get the current time instead.

The former's better; don't use mysql's time, evaluate all the time's in php first and just insert that into the database. This way you're never working with mysql time, just php time.
 
Status
Not open for further replies.
Top