|
Posted by Gordon Burditt on 11/22/07 00:57
>We have some php pages on our intranet at work that have been working
>fine for years. As a result, they rarely get edited.
>
>The page I'm having trouble with is a timesheet entry page which
>uses timestamps to record hours spent on different projects in a
>mysql database. If users try to enter times using the php
>interface, they are getting recorded correctly in the database
>because I can directly access it and see the entries there.
Beware of subtracting times from different clocks. This can result
in problems if one of them is significantly incorrect.
>However the php page that is supposed to display the hours by
>reading back the entries from the database is /not/ correctly
>displaying all the entries. It's never done this before.
What is the problem? (a) Some entries are missing, (b) the hours aren't
correctly computed, or (c) something else?
You've got potentially three different clocks here: (a) The MySQL
server clock, (b) the PHP server clock, and (c) the clock on the
wrist of the guy entering the times. They are probably all incorrect
a little (milliseconds), and possibly by a lot (hours, days, or
years). All of these might have different time zones also.
Nasty things can happen if, for example, the data is taken from the
times the user enters (clock (c)), but you only show entries that
are in the past according to the MySQL SERVER clock(clock (a)).
You might always be missing the latest couple of hours of entries.
If you're displaying a task time for a still-running task (started
but not yet stopped) which clock was used for NOW to calculate
hours-so-far? Which clock was used to calculate the start time?
If you're mixing now() in MySQL with time() in PHP, that may be the
source of the problem.
>Around the time that the page started misbehaving I noticed that
>the clock on the server was ahead of our timezone by some 7 hours
>or so. That was fixed as soon as I noticed it. For some reason
>the ntp client didn't update.
Is the problem now fixed, for entries made entirely after the clock
was reset?
>I'm wondering if the system clock issue had something to do with
>it? Any ideas on where to start the forensics?
You've got several clocks. Which are you using?
>I haven't posted any code at this stage to remain concise, but if
>needed I can post code and sample outputs.
[Back to original message]
|