Page 1 of 1

A strange timeing problem

Posted: Tue Aug 05, 2003 3:09 pm
by banks
Hi

I have just written a Bullettin board type thing in php. I have just one problem with it that I'm completely stuck on.

when I post a reply to a thread, it saves the timestamp with the other post info in my (flatfile) database. using this bit of script:

Code: Select all

//write to thread file

$date_now = time();

$new_thread_line = "$username||$date_now||$post_id||$message\n";

$ftd = fopen("data/$tid","a");

fwrite($ftd, $new_thread_line);

fclose($ftd);
and after posting the user is redirected back to the thread where they can see their new post at the bottom (as you would expect). The page also displays the time in the bar at the bottom using the following code:

Code: Select all

$time_now = time();

echo <<<EndHtml

<tr>

<td bgcolor="#414141" valign="middle" align=left></td>

<td bgcolor="#414141" valign="middle" align=right><h2>All times are GMT. The time now is $time_now</td>

</tr>EndHtml;
now these to calls to the time() function (will eventually be replaced with nice looking dates.) vary by a huge amount despite being called within at most a few seconds. The time between posting a message (clicking submit) and the page fully loading are minimal (less than a few seconds) yet the difference in times on the last post and the page can very up to 30 seconds or more.

Even stranger is that the post is often dated 30 seconds after the page has loaded!

here is a screen shot that illustrates my point:
Image


The main problem here is that I have another function which marks read/unread posts and threads but this is often wrong because all the times are wrong.

Surely the time() and dat functions can't be so inprecise?

If you have any suggestions/ideas/questions please post because this one has stumped me and a few others I've asked.

If you don't understand me I'll try and explain again.

Cheers
?>

Posted: Tue Aug 05, 2003 3:13 pm
by banks
I should point out that the time circled on the left of the screenshot is the time stored when the post is saved and the time circled on the right is the time got when the page is reloaded.

I have also tried date("U") and other date formats but allways get this problem. The difference between the times also varies significantly: sometimes they are only a few seconds out, sometimes they are 30+ seconds out (like in the screen shot). It also varies which one is earlier as well. (sometimes the one on the right is bigger).

Also If I'm asking a really stupid/bad question please let me know what is wrong with it. I'd rather hear that no one understands me or knows what's going on than nothing at all.

Thanks in advance for any ideas/comments.

Posted: Wed Aug 06, 2003 1:06 am
by Tubbietoeter
I understand your problem but don't have any answer to that ... I would understand it if the reload-stamp was the older one, but this way round ...

i can only imagine, that this were a caching problem. you know, when php redirects to the other page it is still working on processing the fist one? maybe you can delay the redirection just to see what happens?
just a guess ... but this really is weird ...

Posted: Wed Aug 06, 2003 4:44 pm
by banks
Hmmmmm

Yes that is the sort of thing I've been thinking of but I can't think of a way around it.

Thanks for your response though - it's good to know that I'm not the only one confused by this.

I will try some more things and post back if I find anything interesting.. Please feel free everyone to continue suggesting things!

cheers

Posted: Wed Aug 06, 2003 5:47 pm
by m3rajk
ok. try making a post. then going back an hour later and replying.
if they have the same timestamp, then let us know

Posted: Thu Aug 07, 2003 3:24 pm
by banks
I'll try that

Another odd thing though, I posted a new thread and the added a reply and the reply was dated 2 seconds before the original thread post????????

and about 20 seconds after the date on the page?

Does this make any sense?

Posted: Thu Aug 07, 2003 3:45 pm
by banks
I might point out that the redirect between the script is done with javascript not php - the reply script when it is successful includes apage which redirects via javascript in an on image load thing. (it was the neatest way I could find).

I mention this only because Tubietoeter said
when php redirects to the other page it is still working on processing the fist one?
and I'm out of reasonable ideas.

where might caching occur?

any other ideas?

thanks for the replies