PHP可以判断服务器os是否为64位吗? [英] Can PHP tell if the server os is 64-bit?
问题描述
我在这里处理Windows.
I am dealing with Windows here.
我知道您可以使用$_SERVER['HTTP_USER_AGENT']
变量来检测浏览页面的浏览器的操作系统,但是PHP可以通过任何方式检测服务器的操作系统吗?
I know you can use the $_SERVER['HTTP_USER_AGENT']
variable to detect the OS of the browser viewing the page, but is the any way that PHP can detect the server's OS?
对于我程序的UI,我使用的是PHP网页.我需要读取注册表中位于64位OS上其他位置的密钥(位于Wow6432Node
密钥下).
For my program's UI I am using a PHP webpage. I need to read a key in the registry that is in a different location on a 64-bit OS (It is under the Wow6432Node
Key).
PHP可以告诉它正在运行什么操作系统吗? PHP可以判断操作系统是64位还是32位吗?
Can PHP tell what OS it is running on? Can PHP tell if the OS is 64-bit or 32-bit?
推荐答案
Note: This solution is a bit less convenient and slower than @Salman A's answer. I would advice you to use his solution and check for PHP_INT_SIZE == 8
to see if you're on a 64bit os.
如果您只想回答32bit/64bit问题,那么像这样的偷偷摸摸的小函数就可以解决问题(利用intval函数基于32/64位处理int的方式.)
If you just want to answer the 32bit/64bit question, a sneaky little function like this would do the trick (taking advantage of the intval function's way of handling ints based on 32/64 bit.)
<?php
function is_64bit()
{
$int = "9223372036854775807";
$int = intval($int);
if ($int == 9223372036854775807) {
/* 64bit */
return true;
} elseif ($int == 2147483647) {
/* 32bit */
return false;
} else {
/* error */
return "error";
}
}
?>
您可以在此处查看运行中的代码: http://ideone.com/JWKIf
You can see the code in action here: http://ideone.com/JWKIf
注意:如果操作系统为64位,但运行的是32位版本的php,则该函数将返回false(32位)...
这篇关于PHP可以判断服务器os是否为64位吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!