A strange timeing problem
Posted: Tue Aug 05, 2003 3:09 pm
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:
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:
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:

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
?>
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);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;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:

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
?>