What can I do in my code today to prevent the expiration of time on Unix in 2038?

For example, I mainly program in PHP. What can I do today to prevent my program from cracking in 2038 due to lack of unix time? I would like to see some specific algorithms, functions or logic that may work to prevent this problem. Thanks.

+6
source share
3 answers

Store the timestamp as an integer of 64 bits or more. I am sure that by that time MySQL will be updated until TIMESTAMP is 32 bits. As for PHP, I do not see any problems there if you are on a 64-bit server.

+6
source

If you plan on using a 32-bit server or PHP binary over the next 25 years, I donโ€™t think this will be a problem.

PHP is an interpreted language, so when you write $stamp = 1358425440; , itโ€™s just a line of text that PHP is reading into, and then allocates X bytes of memory for storage according to how PHP was compiled. Therefore, if you upgrade your PHP binary to a version that supports 64-bit integers, you do not have to change your code. [Theoretically, at least. We all know how PHP likes to change common functions and condemn things.]

The only thing I see in the creation is storing integer values โ€‹โ€‹outside of PHP, i.e. in mySQL. In this case, you just need to make sure that you save your timestamp as UNSIGNED INT, BIGINT or DATETIME.

SIGNED INTs will air Tue, January 19, 2038 03:14:07 GMT, but UNSIGNED INTs will last until Sun, February 7, 2106 06:28:15 GMT.

+3
source

Change

  // 32 bit int timestampSec 

to

  // 64bit long timestampSec 

for internal storage.

+1
source

All Articles