How to determine if my OS is 32 or 64 bit?
I tried using <?php echo php_uname("m"); ?> <?php echo php_uname("m"); ?> , it returns i586 , but I am in the 64-bit version of Windows 7, which I could see in the "Properties of my computers". Therefore, I expect x86_64 in the output. Does anyone know how to define OS architecture in PHP?
I want the same thing for Mac OS X. Any help would be greatly appreciated.
My best guess: even if your OS is 64 bit, your x86 web server also works in WOW64 mode (32 bit). If so, then in pure PHP it should be hard to understand.
My suggestion (thanks to Lee for linking to a similar question) is to use WMI:
$out = array(); exec("wmic cpu get DataWidth", $out); $bits = strstr(implode("", $out), "64") ? 64 : 32; echo $bits; // 32 or 64 php_uname checks the PHP mode of operation , not the OS.
So, if your OS is 64 bit, but php_uname returns i586, because you are using a 32-bit version of PHP.
Knowledge of PHP architecture is perhaps more important than knowledge of OS architecture. For example, if you rely on the OS being 64-bit for decision making in code, you may find code that does not work on a 64-bit OS when PHP runs in 32-bit mode (as it is now). This is actually the exact situation you are in, you expected a result of 64 bits, but got a result for 32 bits, which is due to the PHP mode of operation.
The real solution for your problem is to download and install the 64-bit version of PHP on your 64-bit OS to see 64-bit results.
Here is a simple 1 line of code to determine if PHP is running in a 64-bit or 32-bit version:
empty(strstr(php_uname("m"), '64')) ? $php64bit = false : $php64bit = true; After executing the line above, $php64bit will be either true or false .
Here is a multiline version of the same code:
// detect which version of PHP is executing the script (32 bit or 64 bit) if(empty(strstr(php_uname("m"), '64'))){ $php64bit = false; }else{ $php64bit = true; } This works by checking php_uname for 64 , which would be found if PHP was running in 64 bit mode.