How can I have a 64-bit integer in PHP?

Native 64-bit integers require 64-bit hardware AND the 64-bit version of PHP.

On 32-bit hardware:

$ php -r 'echo PHP_INT_MAX;'
2147483647

On 64-bit hardware:

$ php -r 'echo PHP_INT_MAX;'
9223372036854775807

UPDATE: It does now (tested on AMD quad core, Windows 8.1).

Note that PHP on Windows does not support 64-bit integers at all, even if both the hardware and PHP are 64-bit. See this link for details:

On Windows x86_64, PHP_INT_MAX is 2147483647. This is because in the underlying C code, a long is 32 bit.

However, Linux on x86_64 uses a 64-bit long, so PHP_INT_MAX is going to be 9223372036854775807.


Maybe you could use either the GMP or BCMath extension.