PHP Timezone Database Is Corrupt Error

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

  1. Update the server's PHP version; you said this isn't an option
  2. Use strtotime() to find the date or, if you need or want access to the object-oriented style of DateTime, catch the error with strtotime()

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



Leave a reply



Submit