2

After making a fix to my PHP application on my test server, I pushed it to my production server and the fix didn't work. After tracking it down I found that ksort() was causing index keys to overflow for integers larger than the max 32-bit signed value (2147483648) on my production server only. On my test server it would only overflow for integers larger than the max signed 64-bit integer (9223372036854775808).

Both servers (as fully as I can tell) have the same software configuration

  • Ubuntu 12.10
  • Kernel version: Linux version 3.0.0-15-generic-pae
  • PHP 5.4.6-1ubuntu1.2

    1. CPU on production: AMD Phenom(tm) II X4 910
    2. CPU on test server: AMD Athlon(tm) II X4 620

To reproduce this issue

$arr = array(2147483648 => 1, 5 => 2); ksort($arr); print_r($arr);

Outputs the following on my production server:

Array
(
    [-2147483648] => 1
    [5] => 2
)

The exact same code outputs the following on my test server:

Array
(
    [5] => 2
    [2147483648] => 1
)

I'm trying to figure out what could be causing this. Where should I be looking to narrow down why the servers have different integer sizes. Is it possible that I may have a different version of PHP (even though both appear to be the same) that was compiled with 32bit integers?

4

1 回答 1

0

take a look at PHP_INT_SIZE

http://php.net/manual/en/language.types.integer.php

Integer size can be determined using the constant PHP_INT_SIZE, and maximum value using the constant PHP_INT_MAX since PHP 4.4.0 and PHP 5.0.5.

I would also suggest to increase PHP memory_limit in php.ini or with ini_set().

于 2013-05-01T19:35:44.187 回答