To get the system CPU count in PHP, we can use the shell_exec
function to execute the nproc
command which prints the number of processing units available to the current process.
Here's the code:
main.php62 chars3 lines
The shell_exec
function executes the command passed to it as string and returns the output. In this case, we pass the nproc
command which prints the CPU count to the shell and captures its output in the $cpuCount
variable.
We can then simply print the CPU count using the echo
statement.
gistlibby LogSnag