'PHP how to detect if running on arm64 cpu?

In PHP how can I detect if I am running on an arm64 CPU or not? (as opposed to, for example, an AMD64 CPU)



Solution 1:[1]

The solution seems to be php_uname("m"), but it is trickier than one would expect. This is because we have observed different values for php-running-on-macos (PHP 8.1.3, "arm64") versus php-running-in-linux-docker-container-running-on-macos (PHP 7.4.28, "aarch64"), sooo we have to check for both???

// have been in a situation where MacOS-php says 
// "arm64" while php-in-docker-linux-container-running-on-macos
// says "aarch64"...
$isArm64 = (false!==stripos(php_uname("m"), "aarch64") || false!== stripos(php_uname("m"),"arm64"));

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Danny F