有没有可能获取窗口处理器位数?我想使用php查找窗口处理器位数。我已经编写了代码来查找操作系统和其他属性。请给予建议。谢谢 - Haan
<?php
switch(PHP_INT_SIZE) {
case 4:
echo '32-bit version of PHP';
break;
case 8:
echo '64-bit version of PHP';
break;
default:
echo 'PHP_INT_SIZE is ' . PHP_INT_SIZE;
}
这段代码至少可以告诉你正在运行的PHP版本是32位还是64位。
获取比特数的一种稍微简短且更加健壮的方法。
strlen(decbin(~0));
工作原理:
按位取反运算符,波浪号~,翻转每个比特位。
@see http://php.net/manual/en/language.operators.bitwise.php
将其应用于0会为整数打开每个位。
这将给您的PHP安装程序可以处理的最大数字。
然后使用decbin()将为您以二进制形式表示此数字的字符串表示形式。
@see http://php.net/manual/en/function.decbin.php
strlen将为您提供比特数的计数。
以下是可用函数的示例:
function is64Bits() {
return strlen(decbin(~0)) == 64;
}
PHP_INT_SIZE
更健壮的原因是什么? - jdpPHP_INT_SIZE
自 v4.4 起就存在了。但是无论如何,现在没有人应该再使用 PHP v4 了。 - Turab(请记住,即使您拥有64位处理器、64位操作系统和64位PHP,由于x64-PHP在Windows上的限制,您的整数仍将是32位。)
无论如何...
检查操作系统:
function getOsArchitecture() {
$wmi = new COM('winmgmts:{impersonationLevel=impersonate}//./root/cimv2');
$wmi = $obj->ExecQuery('SELECT * FROM Win32_OperatingSystem');
if (!is_object($wmi)) {
throw new Exception('No access to WMI. Please enable DCOM in php.ini and allow the current user to access the WMI DCOM object.');
}
foreach($wmi as $os) {
return $os->OSArchitecture;
}
return "Unknown";
}
function getProcessorArchitecture() {
$wmi = new COM('winmgmts:{impersonationLevel=impersonate}//./root/cimv2');
if (!is_object($wmi)) {
throw new Exception('No access to WMI. Please enable DCOM in php.ini and allow the current user to access the WMI DCOM object.');
}
foreach($wmi->ExecQuery("SELECT Architecture FROM Win32_Processor") as $cpu) {
# only need to check the first one (if there is more than one cpu at all)
switch($cpu->Architecture) {
case 0:
return "x86";
case 1:
return "MIPS";
case 2:
return "Alpha";
case 3:
return "PowerPC";
case 6:
return "Itanium-based system";
case 9:
return "x64";
}
}
return "Unknown";
}
function functionName() {
function is_32bit(){
return PHP_INT_SIZE === 4;
}
if( is_32bit() ) {
// do 32 bit stuffs
}
function bits() {
return PHP_INT_SIZE * 8;
}
echo 'Php running on '.bits(). ' bits system';
另一种选择:
function IsAtLeast64Bit()
{
return defined('PHP_INT_SIZE') && PHP_INT_SIZE >= 8;
}
只有在定义了PHP_INT_SIZE时,它才返回TRUE。这适用于所有64位系统。未来具有超过64位的系统也将得到管理。
<?php echo $_SERVER['HTTP_USER_AGENT']; ?>
这段代码存储在变量中,您可以将其分解并从中获取信息。