Rick Rainey
Rick Rainey

Reputation: 11256

How to determine the number of cores on a machine using PHP?

Is there a built-in function in PHP that will return the number of cores on a machine? I’m running on Mac OS X 10.9.3 (Mavericks).

Upvotes: 0

Views: 177

Answers (1)

dmullings
dmullings

Reputation: 7200

There isn't a php built in function, but you can execute a command to get the result. On OSX 10.9.3 the following will return the number of cores.

$output = '';
$command = "sysctl hw.ncpu | awk '{print $2}'";
exec($command,$output);
echo $output[0];

Upvotes: 1

Related Questions