13

Is it possible to identify Linux 32 or 64 bit, using PHP?

phpinfo() 

returns

Linux infong 2.4 #1 SMP Mon Oct 10 09:34:36 UTC 2011 i686 GNU/Linux 

It's shared hosting so I cant use command line.

user unknown
  • 35,537
  • 11
  • 75
  • 121
Narek
  • 3,813
  • 4
  • 42
  • 58
  • 6
    Why does it matter why does it matter? I'ts a question, answer if you can. – shift66 Jan 17 '12 at 08:01
  • 1
    I see that you can't access the command line, but can you still execute shell scripts? Try taking a look at `[shell_exec()](http://php.net/manual/en/function.shell-exec.php)`. If you are able to do this, you could easily punch in a shell statement to get it. – Tyler Crompton Jan 17 '12 at 08:02
  • 1
    `i686` means it is running in 32 bit mode. Regarding PHP you should rather check PHP_INT_MAX – mario Jan 17 '12 at 08:02
  • `It's shared hosting so I cant use command line.` - a funny one:) – Your Common Sense Jan 17 '12 at 08:06
  • Thanks for suggestions! @tangrs I have program with two versions, and don't know what to install. Don't worry, I don't want to hack CIS server. – Narek Jan 17 '12 at 08:13
  • If you are reaching the limits of storing an integer then I would think again about your edesign. – Ed Heal Jan 17 '12 at 08:28
  • This is important when using PHP time functions. – TecBrat Sep 30 '13 at 19:24

1 Answers1

23

Do a simple test:

var_dump(is_int( 9223372036854775807 ));

For 32-bit environment it will return false as this number is much bigger that maximum 32-bit integer. For 64-bit environment it will return true.


Or use PHP_INT_MAX as mario suggested in comments.

echo (PHP_INT_MAX == 2147483647)?'32-bit':'64-bit';

Or use PHP_INT_SIZE:

echo (PHP_INT_SIZE * 8) . '-bit';
Konrad Dzwinel
  • 36,825
  • 12
  • 98
  • 105