Search code examples
phpcentosstrtotimeopensuse

PHP: Why strtotime conversion give different values and only limited to a particular date?


I have two web servers with different operating system.

SERVER 1 run in Centos 5 with LAMP Server. PHP Version 5.3.21

SERVER 2 run in openSUSE 11.3 with LAMP Server. PHP Version 5.3.5

Both PHP Configurations are same. Some are the default.

I have a php file with code like this:

<?php
/* TEST STRTOTIME */
echo "<br /><br />".strtotime("2038-01-01");
echo "<br /><br />".strtotime("2039-01-01");
?>

When i run this file in SERVER 1, the result is :

2145934800

2177470800

but when i run this file in SERVER 2, the second conversion does not produce anything. Only show result is :

2145891600

Why the results of the conversion on both servers give different values​​? whereas the same file. Why on SERVER 2 could not convert on the above date 2038-01-01? Is there a solution to this problem?


Solution

  • Your remote server is probably 32-bit. You will need to have a 64-bit server to process dates after roughly 2038.

    The reason is your remote server stores its integers as signed 32 bit integers. The maximum number that can be stored as a signed 32 bit integer is 2,147,483,647 (2^31 - 1). Since this number is the number of seconds after Jan 1st, 1970 (Unix epoch), you can see that the number will eventually be exhausted (and possibly overflow if not bounds checked).

    Example

    Image Source: Wikipedia