2011年1月14日 星期五

How to get the path of the PHP BIN from PHP?

You can use:
constant(not recommend)
PHP_BINDIR gives the directory where the php executable is found.

method(recommend)

public function getPHPExecutableFromPath(){
$paths = explode(PATH_SEPARATOR, getenv('PATH'));
foreach ($paths as $path) {
$php_executable = $path . DIRECTORY_SEPARATOR . "php" . ("WIN" === strtoupper(substr(PHP_OS, 0, 3)) ? ".exe" : "");
if (file_exists($php_executable) && is_file($php_executable)) {
return $php_executable;
}
}
return false; // not found
}

沒有留言:

wibiya widget