473,666 Members | 2,238 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1464
>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
2008
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 to convert an utc timestamp held in a mysql database into a display field in the relevant local time ( not doing so can be most tedious when you live in GMT+12! ). There must be a simple way... I've got linux and mysql available if either of...
0
1335
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 convert but I was wondering if the language itself supports the conversion which I would prefer using. Any other tips is appreciated
13
7020
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 this is C#. Can this be done ? If so how ? Please note setting the culture does not impact the timezone and a culture (like en-US) may have many timezones.
0
1145
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 http://www.postgresql.org/docs/7.4/static/datetime-keywords.html it notes that time zone information is system dependent, (I interpret to mean that anything I find in /usr/share/zoneinfo on linux should be supported, can someone confirm that?) so how can an external app determine which timezones are...
1
2129
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 different timezones? For example: Date1 = 11:30, 4/18/06, NY Date2 = 16:30, 4/18/06, LN These times should be considered equal (since of course LN time is +5 NY
1
1475
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. Please use the date.timezone setting, the TZ environment variable or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We had...
3
3081
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 having to update a database constantly with the times and dates that certain countries set their clocks back or forward. Can this be done, or do I need to connect to a time server? Ideally, I need a time server that will return a JavaScript...
7
3853
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 timezones from a PHP script or compiled 'C' program? Given a specific timezone, how do I get the time adjustment from UTC (which can vary, based on daylight savings rules)?
27
5310
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 there a smaller and more practical set? If not, some suggestions on how to handle the registration form effectively would help me a lot. thanks Sanjay
0
8440
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8866
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8781
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8638
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7381
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5662
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4193
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2769
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2006
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.