473,378 Members | 1,470 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

php code, timezones affecting mysql?

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.

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.

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.

I'm wondering if the system clock issue had something to do with
it? Any ideas on where to start the forensics?

I haven't posted any code at this stage to remain concise, but if
needed I can post code and sample outputs.

--
Troy Piggins
Nov 22 '07 #1
2 1449
>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.
Nov 22 '07 #2
* Gordon Burditt is quoted
* & my replies are inline below :
>>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?
Sorry I omitted that. Some entries are missing, just displaying
on the page as though there is no entry at all. Some entries are
displaying the correct no of hours in the correct day.
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.
c) above is not an issue. The actual times are not entered, just
durations. So they would just enter that they worked on XYZ
project for 4 hours on 22/11/07.

I hadn't thought about the mysql server clock. Do you mean
mysqld has it's own time keeping mechanism? Or do you mean the
machine that mysqld is running on? Both the apache/php and
mysqld servers are the same machine.

I corrected the time on the machine by using the 'ntpdate' command
as root IIRC.
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.
I understand, but as mentioned above it's not that sofisticated.
>>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?
Well, the problem persists for some entries made around that time
- maybe a week or 2 before the problem was pointed out to me.
Some of the guys enter their timesheets directly into the
timesheet php interface daily, while others write it in a diary
and just add it when they need to submit their timesheets.
That's why I didn't notice it sooner.

I have just tested some for this current week and it seems to be
working ok again.

Just curious about the reason behind it so it doesn't happen
again.
>>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?
Hopefully this is answered above.

Thanks for assisting.

--
Troy Piggins
Nov 22 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Steve | last post by:
I'm going slowly mad here... What I want to do is to be able to convert from a timezone name eg "Europe/London" to an offset from UTC ... in this case it's +1 hour at the moment. The end result is...
0
by: B. G. Mahesh | last post by:
hi I am using PHP 4.x and MySQL. The database has the list of countries, cities and timezones. I would like to convert the time from one zone to another zone . It is not that difficult to...
13
by: Michael | last post by:
I would like to set the timezone of a thread to allow me to calculate the UTC time for data sourced from a number of time zones. Although this can be done in C and C++, I annot find how to do...
0
by: Robert Treat | last post by:
I am trying to figure out if there is a way to determine the timezones supported in postgresql from within the database. If you look at...
1
by: Flack | last post by:
Hey guys, I need to compare two times that the user selects. The user selects the hour, date, and timezone (which can be either NY, LN, or HK timezones). How can I compare two dates of...
1
by: glini | last post by:
Hi all, I have a strange problem. Iset up php 5.1.6 on my Solaris10 box and after that i get errors on my webbpage: "Warning: date() : It is not safe to rely on the system's timezone settings....
3
by: Daz | last post by:
Hello everyone. I am creating a JavaScript project which will allow users to see what time it is in other countries. I am wondering if there's any way to have the server work this out, without...
7
by: David T. Ashley | last post by:
In a web database (PHP), per user, I'd like to allow each user to specify their timezone (this would change how times are adjusted for display for that user). How do I enumerate all possible...
27
by: Sanjay | last post by:
Hi All, I am using pytz.common_timezones to populate the timezone combo box of some user registration form. But as it has so many timezones (around 400), it is a bit confusing to the users. Is...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.