PHP Timezone database is corrupt error
The problem was file permissions. I gave the apache2 user read & execute access to usr/share/zoneinfo and etc/localtime. Before, I hadn't set the parents of local time to the right permissions as well. i.e. I only changed the permissions of localtime and zoneinfo without changing the permissions of their parent directories. So stupid! Stepping away from a problem and getting back to it is always useful.
`PHP Fatal Error: date(): Timezone database is corrupt` on redhat 6.9, nginx, php-fpm
Reinstalling timezonedb with pecl solves my problem.
Is this a php bug, or is something wrong with my timezone/PHP settings?
My bet is on a PHP bug. I know that PHP used to have issues with catching exceptions thrown in constructors, and that seems to be what's going on here.
Because it's a bug, your options are
- Update the server's PHP version; you said this isn't an option
- Use
strtotime()
to find the date or, if you need or want access to the object-oriented style ofDateTime
, catch the error withstrtotime()
For example:
<?php
try {
if (@strtotime($str) !== false) {
$x = new DateTime($str);
} else {
throw new Exception("Failed to parse string ({$str})");
}
} catch ( Exception $e ) {
echo $e->getMessage();
}
Related Topics
Do I Need to Escape Backslashes in PHP
Uploading a File via Ajax with PHP
PHP Undefined Index Error $_Files
Getting Warning "Header May Not Contain More Than a Single Header, New Line Detected"
Fatal Error: Call to Undefined Method MySQLi_Stmt::Get_Result()
How to Get Wordpress Post Featured Image Url
When Is It Good to Use Pass by Reference in PHP
How to Ipc Between PHP Clients and a C Daemon Server
Simpler Way to Check If Variable Is Not Equal to Multiple String Values
How to Convert PHP Regex to JavaScript Regex
Printing Content of a Xml File Using Xml Dom
How to Decode a JSON String in PHP
Upload Multiple Images with Codeigniter
Remove First 4 Characters of a String with PHP
How to Backup MySQL Database in PHP
How to Generate a Custom Menu/Sub-Menu System Using Wp_Get_Nav_Menu_Items in Wordpress