2147483647 is a weird number in PHP
Yesterday I was working on a client box to install Sphinx Search into vBulletin 3.7.1 version. I installed also a little product I made that will use the eBay Partner Network affiliate link, instead of a regular eBay link. This is where I encountered the 2147483647 integer issue.
The product (epnlinks) does link insertion without any preg_match() function or any other replace scheme that slows the server down, like the product you find at vBulletin.org site. Because I work most of the time on 64 bits machines, I never really cared to check if the PHP version is also 64 bits, on the X64 machine. The logic tells me that it should always be. Well, it is not. When I entered my client campaign ID, to my BIG surprise, it changed from the 10 digits number to 2147483647.
“This can’t be right, what the hell is going on here?”
Running a simple command like:
$ php -r 'var_dump(PHP_INT_MAX);' int(2147483647)
made me understand what was the problem.
The client is running PHP 32bits, on a 64bits machine. Simply insane.
The maximum value an INT can have on PHP 32bits is 2147483647, so any value superior to that will turn into the magic number mentioned above. For 64 bit systems, the maximum signed integer value for is 9223372036854775807. Another reason to upgrade?
I hope this helps other developers, because… for a moment I thought there is a ghost into the Unix box… changing the number for me.
Tags: PHP