get system architecture in php

To get the system architecture in PHP, you can use the PHP_OS constant and check for specific architecture values.

Here's an example code snippet:

main.php
if (strpos(strtolower(PHP_OS), "win") === 0) {
    echo "This system architecture is 32-bit Windows";
} elseif (strpos(strtolower(PHP_OS), "darwin") === 0) {
    echo "This system architecture is 64-bit macOS";
} elseif (strpos(strtolower(PHP_OS), "linux") === 0) {
    $arch = strtolower(exec("uname -m"));
    if ($arch == "x86_64") {
        echo "This system architecture is 64-bit Linux";
    } else {
        echo "This system architecture is 32-bit Linux";
    }
} else {
    echo "Unknown system architecture";
}
521 chars
15 lines

This code snippet will output the system architecture based on the operating system. For Windows, it will output if it's 32-bit or 64-bit. For macOS, it will output 64-bit since all modern Macs are 64-bit. For Linux, it will execute the uname -m command to get the machine hardware name and check if it's 64-bit or not.

gistlibby LogSnag