PHP command line error : Timezone database is corrupt - php

My date.php is -
<?php
echo date('Y');
When I execute php -f date.php on my staging machine, I get error -
PHP Fatal error: date(): Timezone database is corrupt - this should *never* happen!
in /home/staging/test/date.php on line 2
But when I execute the same on my local / dev machine it works. Although on both staging and local machines, permissions on /etc/localtime and /usr/share/zoneinfo/ are the same.
But output of file /etc/localtime vary on both machines.
Local (php5.3.5) :
/etc/localtime: timezone data, version 2, 4 gmt time flags, 4 std time flags, no leap seconds, 4 transition times, 4 abbreviation chars
Staging (php5.3.10) :
/etc/localtime: timezone data, version 2, 1 gmt time flag, 1 std time flag, no leap seconds, no transition times, 1 abbreviation char
While trying to find what the issue is I found this link from SO. I am confused over the accepted answer. My apache user is not executing the script.
What seems to be the problem? How do I resolve this issue?

For various reasons, PHP ships with its own timezone database - it is possible to use the system TZDB by configuring the software differently at compile time.
The PHP timezonedb is implemented as C code (lots of defines) - hence you need to recompile PHP to get it working.
If your PHP interpreter is not explicitly configured to use the OS timezoneDB, then you really need to investigate why the executable is corrupt.

Please check permission of your timezone files.It might have changed when you have install some rpms.
change the permission to 655
Also check following files:
/usr
/lib
/share
/etc

My problem was that I was running php-fpm in chroot mode. I changed it to run without a chroot, and then the error went away.

Related

Variable not showing nor the php code is debug ...why? [duplicate]

When I start debugging the process stays there at 57% and says "waiting for XDebug session".
This is a duplicate post on StackOverFlow, but I tried all the answers, nothing worked.
It was working fine until before two days. I don't know what went wrong.
Having used Eclipse to launch xdebug sessions in Firefox for ever now, all of a sudden 23/4/2013 it would not launch xdebug using Firefox. It gave me the launch 57% and hang problem.
It was quite happy to launch xdebug sessions in IE/Chrome/Safari/Opera but not Firefox.
The only thing I changed around this time was I upgrades my java runtime to 1.7.0_21 from a previous version ( cannot remember which but I did jump more than one release so it was probably 1.7.0_19 )
I took a look at the project log file, Check your projects workspace folder for a subfolder called .metadata where there should be a .log file, there is one of these for each project so be sure you are looking at the correct one.
This is what was in mine:
!SESSION 2013-04-23 11:06:21.238
----------------------------------------------- eclipse.buildId=M20130204-1200 java.version=1.7.0_21
java.vendor=Oracle Corporation BootLoader constants: OS=win32,
ARCH=x86, WS=win32, NL=en_GB Command-line arguments: -os win32 -ws
win32 -arch x86
!ENTRY org.eclipse.ui.browser 4 0 2013-04-23 11:07:32.584 !MESSAGE
Launching C:\Program Files\Mozilla Firefox\firefox.exe has failed.
!STACK 0 java.io.IOException: Cannot run program "C:\Program":
CreateProcess error=2, The system cannot find the file specified at
java.lang.ProcessBuilder.start(Unknown Source) at
java.lang.Runtime.exec(Unknown Source) at
java.lang.Runtime.exec(Unknown Source) at
java.lang.Runtime.exec(Unknown Source) at
org.eclipse.ui.internal.browser.browsers.MozillaBrowser$BrowserThread.openBrowser(MozillaBrowser.java:94)
at
org.eclipse.ui.internal.browser.browsers.MozillaBrowser$BrowserThread.run(MozillaBrowser.java:165)
Caused by: java.io.IOException: CreateProcess error=2, The system
cannot find the file specified at java.lang.ProcessImpl.create(Native
Method) at java.lang.ProcessImpl.(Unknown Source) at
java.lang.ProcessImpl.start(Unknown Source) ... 6 more
Because I saw this line
java.io.IOException: Cannot run program "C:\Program": CreateProcess error=2,
It made me thinks that for some reason java could no longer cope with folder names with spaces in them (very strange), so I changed the eclipse preferences and used the 8.3 naming convension C:\PROGRA~1\MOZILL~1\firefox.exe
Now it launches the xdebug session again!!
This is very strange as it does not seem to have problems with
C:\Program Files\Opera\opera.exe OR
C:\Program Files\Safari\Safari.exe OR
C:\Program Files\Internet Explorer\iexplore.exe
So all I can think of is that it does not like 2 folder names with spaces in them for some obsqure reason, because it wont launch firefox from C:\Program Files\Mozilla Firefox\firefox.exe
I assume it launches IE from a similiar folder named address as it is the default browser on this system.
Anyhow, the solution for me was to change the eclipse preferences ->General -> Web Browser -> Firefox
to use the 8.3 DOS directory naming convension.
Hope this helps
riggsfolly's analysis and solution are both correct, however for some reason my eclipse would not allow me to use the DOS 8.3 naming convention. As an alternative for those who run into the same issue you can try the following:
Create a parallel folder structure but do it without spaces (eg. "C:\ProgramFiles86\MozillaFirefox\")
Download and install firefox, using the custom installation options to install to your new 'spaceless' directory
In eclipse preferences ->General -> Web Browser: Make a new entry (eg. "Firefox2") and point it at your new installation (eg. C:\ProgramFiles86\MozillaFirefox\firefox.exe").
Finishing touch - use Mozilla Sync between the two browsers so you don't have to worry about outfitting your new Firefox.
And the easiest way I used to find out the 8.3 compatible windows path of Mozilla Firefox is as below.
C:\>dir .* /x
Volume in drive C has no label.
Volume Serial Number is XXXX-XXXX
Directory of C:\
File Not Found
C:\>dir *.* /x
Volume in drive C has no label.
Volume Serial Number is XXXX-XXXX
Directory of C:\
07/14/2009 08:50 AM <DIR> PerfLogs
04/01/2013 07:32 PM <DIR> PROGRA~1 Program Files
05/14/2013 01:50 PM <DIR> PROGRA~2 Program Files (x86)
01/17/2013 01:43 PM <DIR> Users
05/12/2013 05:46 AM <DIR> Windows
C:\>cd PROGRA~2
C:\PROGRA~2>dir *.* /x
Volume in drive C has no label.
Volume Serial Number is XXXX-XXXX
Directory of C:\PROGRA~2
05/14/2013 01:50 PM <DIR> .
05/14/2013 01:50 PM <DIR> ..
05/14/2013 01:50 PM <DIR> COMMON~1 Common Files
03/05/2013 10:50 AM <DIR> Google
07/14/2009 11:07 AM <DIR> INTERN~1 Internet Explorer
04/19/2013 06:03 PM <DIR> Java
04/14/2013 10:16 PM <DIR> MOZILL~1 Mozilla Firefox
04/15/2013 10:57 AM <DIR> MOZILL~2 Mozilla Maintenance Service
C:\PROGRA~2>cd MOZILL~1
C:\PROGRA~2\MOZILL~1>
I had a similar problem. mine stayed at 72%. I solved my issue by setting
xdebug.mode = debug
in the php.ini file.
I restarted the apache server now it works fine.
In addition to RiggsFolly's life-saving solution, maybe the following is useful for anyone.
Issue 1: different path on 32 bits and 64 bits Windows 7
On 32 bits Windows 7, the path is:
C:\PROGRA~1\MOZILL~1\firefox.exe
On 64 bits Windows 7, the path is:
C:\PROGRA~2\MOZILL~1\firefox.exe
(Note the different figure behind PROGRA~ , as I figured out by Abu Sithik's post)
Issue 2: Where to set the path?
You should do the setting (as RiggsFolly had already correctly said) in:
Window > Preferences > General > Web Browser > Firefox > Edit
and NOT (as I did intuitively) in Run > Debug Configurations > Web browser > Firefox - Internal Server.
At least, as far as I tried out (but I'm a relative Eclipse novice) it seems this setting doesn't influence the path that Eclipse/xdebug/java uses to start the browser in an xdebug session.
I hope this helps anyone prevent wasting time as I did fiddling around in vain, when switching between computers running resp. 32 bits and 64 bits Windows, and having to change the path to the firefox executable, until at a certain moment by luck I got the correct ways as indicated above...
I have the same problem, but suddently works when I select de 'Default system web browser instead of Firefox directly. My default web browser is Firefox and now it starts oks.
I hope this helps.

Why is the default PHP time zone "Europe/Moscow" in my system?

I have been running PHP on many Ubuntu versions and all of them exhibit the same "feature". When I dump the output of the phpinfo() function to a web page, I see the following:
Default timezone: Europe/Moscow
when both php.ini files (/etc/php/7.?/apache2/php.ini and /etc/php/7.?/cli/php.ini) have the date.timezone setting commented out, as it is the case by default.
My system's time zone has always been set correctly to Europe/Istanbul:
$ file /etc/localtime
/etc/localtime: symbolic link to /usr/share/zoneinfo/Europe/Istanbul
However, PHP thinks my local time zone is Europe/Moscow instead. Currently, these two time zones are similar, but this was not so in the past and may not be so in the future.
To solve, this problem each time these php.ini files are being updated (for example, after a patch or system upgrade) I have to manually edit them and set:
date.timezone = Europe/Istanbul
What is the reason of this strange behavior and what can I do to solve this problem?
Currently, I am on Ubuntu 19.10 with PHP 7.3, but the problem exists in previous OS and PHP versions too.
You said yourself that Moscow and Istanbul are in the same timezone. If you are worried that your PHP programs may suffer functionality in the event that this were to ever change you can may use the function
date_default_timezone_set ( string $timezone_identifier ) : bool
to override the php.ini file. I have included a link to the documentation.

website displaying wrong timezone

I been breaking my brain about this one…
Server Location: San Francisco
Server Configuration: Ubuntu + LEMP
App: Wordpress
Ok so I set Ubuntu's time to my current time and changed the time zone to HST which is the one Im at and restarted cron.
I set the php.ini timezone to Pacific/Honolulu and set Wordpress Settings/Timezone to Pacific/Honolulu
Restarted nginx and php...
However when I
<?php echo date('e'); ?>
it displays UTC…
am I missing anything? help!
Try following,
<?php
date_default_timezone_set('America/Los_Angeles');
echo date_default_timezone_get() . ' => ' . date('e') . ' => ' . date('T');
?>
Set the timzone within the script.
date_default_timezone_set('PST');
date('e');
What was your system timezone set to when you've originally started nginx?
Did you actually shutdown nginx, and then started it up from scratch, or did you simply made it re-read its configuration file? (FYI: the popular cat /var/run/nginx.pid | xargs kill -HUP would not result in a restart.)
Your best bet would probably be to do something like sudo sh -c "cat /usr/share/zoneinfo/Pacific/Honolulu > /etc/localtime", remove any timezone mentions from the individual apps, and then properly shutdown and startup the whole server.
In your php.ini file make sure you set:
date.timezone = "America/Los_Angeles"
And then change your server time to the appropriate timezone using:
sudo dpkg-reconfigure tzdata
Better late than never, so I'll chime in here. It's actually WordPress and the weird decision to set the default timezone back to UTC no matter what your INI settings might be. This delightful gem can be found in wp-settings.php (link is for trunk version, marked line might be off in the future).
I guess they did it to keep their internal time calculations easy and on a common base. I do understand the intention behind this but still think it's awkward and surely has caused lots of confusion and trouble for users and developers (like me just now). They could've kept it internal.
Anyways, the bottom line is: When doing your own time calculations in a theme or plug-in or whatever, be sure to explicitly set the timezone beforehand.
Just using time() and thinking you're good to go might lead to headaches. You can get what is set in the settings panel via get_option('timezone_string') and for example use that in conjunction with date_default_timezone_set.
Weston Ruter summed this all up just fine and also suggests using PHP's date and time related classes and explicitly setting the timezone for them.

Max execution time

I have a site which is hosted on a dev site for demonstration to the client, and everything works without problem. However, when I download the files and database to my local EasyPHP installation, I receive the following error:
Fatal error: Maximum execution time of
30 seconds exceeded in C:\Program
Files (x86)\EasyPHP-5.3.4.0\www\PC
Estimating\classes\database.class.php
on line 23
The database details for the connection are correct, as the Database object is already used on part of the template before this error is shown.
My question is, why does the system work fine on a live server, but not on EasyPHP?
You should check the max_execution_time setting in the php.ini files on your server and on your local installation.
btw... what is done in line 23 ?
Copied from my comment to make it easier to find the solution:
some things really runs slower on windows... while on mac/unix the php connects to mysql using a file socket while it should use tcpip in windows. Try using "127.0.0.1" instead of "localhost" when connecting to the db
These issue have two possible solutions:
1) Increase the max_execution_time in your php.ini . First of all, locate this file, and then edit it. Locate this line:
max_execution_time=30
and replace by:
max_execution_time=120
And then restart your webserver.
This will increase from 30 seconds to 120 seconds. You can increase even more, according to your application needs.
2) If this setting doesn't solve the problem, you may have to look into your PHP application, because there may be an infinite loop or something similar.
More details about this problem:
https://www.copahost.com/blog/increase-php-max-execution-time/
Because your PC is slow compared to server and/or your code is really badly optimised

Why is my PHP error log lagging behind by 2 hours?

When checking php.ini, from both phpinfo and php -i on the command line, my timezone is set to Africa/Johannesburg. So my timezone is GMT +2.
I wrote a tiny snippet to check the time is right as follows:
echo date('h:i A', time());
echo '<br />' . ini_get('date.timezone');
and this outputs the correct time, matching with my localmachine's system time.
However, when I look at my php error log, the time on each error log item is behind by exactly two hours? Why is this, and how can I fix this.
Also having issues with Zend Cache, and i think this time issue is causing it.
It sounds like PHP is configure with one timezone, and the server it is running on is set to a different time zone (possibly GMT / UTC). This means all file operations etc will be working on a different timezone to your PHP scripts.
Check the system timezone of your server.
Google-fu: read what the PHP official site writes.

Categories