public static function getBinary()
{
// Custom PHP path
if (self::$_binary === null) {
if ((self::$_binary = getenv('PHP_BINARY_CUSTOM')) === false) {
self::$_binary = PHP_BINARY;
}
}
// HHVM
if (self::$_binary === null && self::isHHVM()) {
if ((self::$_binary = getenv('PHP_BINARY')) === false) {
self::$_binary = PHP_BINARY;
}
self::$_binary = escapeshellarg(self::$_binary) . ' --php';
}
// PHP >= 5.4.0
if (self::$_binary === null && defined('PHP_BINARY')) {
self::$_binary = escapeshellarg(PHP_BINARY);
}
// PHP < 5.4.0
if (self::$_binary === null) {
if (PHP_SAPI == 'cli' && isset($_SERVER['_'])) {
if (strpos($_SERVER['_'], 'phpunit') !== false) {
$file = file($_SERVER['_']);
if (strpos($file[0], ' ') !== false) {
$tmp = explode(' ', $file[0]);
self::$_binary = escapeshellarg(trim($tmp[1]));
} else {
self::$_binary = escapeshellarg(ltrim(trim($file[0]), '#!'));
}
} elseif (strpos(basename($_SERVER['_']), 'php') !== false) {
self::$_binary = escapeshellarg($_SERVER['_']);
}
}
}
if (self::$_binary === null) {
$binaryLocations = array(PHP_BINDIR . '/php', PHP_BINDIR . '/php-cli.exe', PHP_BINDIR . '/php.exe');
foreach ($binaryLocations as $binary) {
if (is_readable($binary)) {
self::$_binary = escapeshellarg($binary);
break;
}
}
}
if (self::$_binary === null) {
self::$_binary = 'php';
}
return self::$_binary;
}