Reputation: 953
Is it possible to get the window processor bit?? I want to find the window processor bit using php?? I have coding to find the operating system and other properties. Kindly advice. Thanks - Haan
Upvotes: 16
Views: 18952
Reputation: 272006
Assuming that you want to know the bitness of the PHP executable (not the microprocessor or the operating system):
Generally speaking, the size of an integer should be 4 bytes on 32-bit and 8 bytes on 64-bit platforms:
switch (PHP_INT_SIZE) {
case 4:
echo '32-bit version of PHP';
break;
case 8:
echo '64-bit version of PHP';
break;
default:
echo 'unusual PHP_INT_SIZE ' . PHP_INT_SIZE;
break;
}
You may also look at the output of phpinfo(INFO_GENERAL)
. Search the Architecture
and Configure Command
lines for keywords such as i586, x86_64, AMD64, x86 and x64.
Upvotes: 44
Reputation: 3492
Another alternative:
function IsAtLeast64Bit()
{
return defined('PHP_INT_SIZE') && PHP_INT_SIZE >= 8;
}
It returns only TRUE, if PHP_INT_SIZE is defined. This should apply for all 64-Bit systems. Future systems with more than 64 bits are managed too.
Upvotes: 0
Reputation: 5741
function bits() {
return PHP_INT_SIZE * 8;
}
echo 'Php running on '.bits(). ' bits system';
Upvotes: 0
Reputation: 473
A slightly shorter and more robust way to get the number of bits.
strlen(decbin(~0));
How this works:
The bitwise complement operator, the tilde, ~, flips every bit.
@see http://php.net/manual/en/language.operators.bitwise.php
Using this on 0 switches on every bit for an integer.
This gives you the largest number that your PHP install can handle.
Then using decbin() will give you a string representation of this number in its binary form
@see http://php.net/manual/en/function.decbin.php
and strlen will give you the count of bits.
Here is it in a usable function
function is64Bits() {
return strlen(decbin(~0)) == 64;
}
Upvotes: 7
Reputation: 3541
You could write a function like this:
function is_32bit(){
return PHP_INT_SIZE === 4;
}
Then you could use it like this:
if( is_32bit() ) {
// do 32 bit stuffs
}
Upvotes: 1
Reputation: 2322
If you have the COM
extension installed (in php.ini) you can call the windows WMI service.
(Remember though that you event if you have a 64-bit processor, 64-bit OS and 64-bit PHP, your integers are still going to be 32-bit due to a limitation in x64-PHP on Windows.)
Anyway...
To check the OS:
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";
}
or, check the physical processor:
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";
}
Upvotes: 2
Reputation: 445
<?php echo $_SERVER['HTTP_USER_AGENT']; ?>
it is contained in the variable, you could explode that and derive it from that
Upvotes: -2