Timezone in PHP

I had a funny problem with my Cacti installation the other day — all the graphs were missing the last hour.  The system was doing updates correctly, but new data was being entered onto the graph at “T-minus-one-hour”.

The first thing I thought of was a problem caused by daylight savings (the state of Queensland doesn’t observe DST, and those Aussie states that do transitioned a week or so ago).  But where?  And why now all of a sudden — I’ve been running Cacti for a few years now.

Strangely, the entries in the cacti log file were timed correctly, except for the entry made by the poller job at completion.  So it seemed that it was just the poller job — which runs from cron — that had a dodgy setting.  I checked for TZ environment variables in apache and cron, and found nothing.

Then I thought of running phpinfo.  If you’ve not done PHP work before, phpinfo() is a built-in function in PHP that dumps a very thorough list of current configuration settings and environment details.  Running phpinfo() through the web server showed that there is a default timezone setting in PHP that was defaulting to “Australia/ACT”!  Changing this to “Australia/Brisbane” in php.ini fixed the PHP code running through Apache, but didn’t change the graphs…  On Gentoo, there is a separate php.ini for CLI PHP — making the same change there fixed the problem.

So why was this not an issue last DST change?  I’ve upgraded to PHP 5 during the last year, and looking through the php.ini from the old PHP 4 installation showed no timezone setting.  So perhaps PHP 4 picked up timezone from the shell environment…

So I now have correct graphs in Cacti, and posts in this blog (Polarblog is PHP-based) show up in correct local time again.  One more for the good guys! 🙂

Leave a comment