A strange timeing problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
banks
Forum Newbie
Posts: 5
Joined: Tue Aug 05, 2003 3:09 pm

A strange timeing problem

Post 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
?>
User avatar
banks
Forum Newbie
Posts: 5
Joined: Tue Aug 05, 2003 3:09 pm

Post 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.
Tubbietoeter
Forum Contributor
Posts: 149
Joined: Fri Mar 14, 2003 2:41 am
Location: Germany

Post 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 ...
User avatar
banks
Forum Newbie
Posts: 5
Joined: Tue Aug 05, 2003 3:09 pm

Post 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
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

Post 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
User avatar
banks
Forum Newbie
Posts: 5
Joined: Tue Aug 05, 2003 3:09 pm

Post 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?
User avatar
banks
Forum Newbie
Posts: 5
Joined: Tue Aug 05, 2003 3:09 pm

Post 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
Post Reply