$php_path = $php;
if (defined("PHP_WINDOWS_VERSION_MAJOR")) {
/* On Windows it should be in the same dir as php.exe in most of the cases. */
- $php_path = dirname($php);
-
- if (is_dir($php_path) && file_exists("$php_path/php-cgi.exe") && is_executable("$php_path/php-cgi.exe")) {
- return "$php_path/php-cgi.exe";
+ $cgi_path = dirname($php) . "/php-cgi.exe";
+ if (is_executable($cgi_path)) {
+ return $cgi_path;
}
} else {
- for ($i = 0; $i < 2; $i++) {
- $slash_pos = strrpos($php_path, "/");
- if ($slash_pos) {
- $php_path = substr($php_path, 0, $slash_pos);
- } else {
- return FALSE;
- }
+ /* Try in the same path as php, for the case where php is installed. */
+ $cgi_path = dirname($php) . "/php-cgi";
+ if (is_executable($cgi_path)) {
+ return $cgi_path;
}
- if ($php_path && is_dir($php_path) && file_exists($php_path."/cgi/php-cgi") && is_executable($php_path."/cgi/php-cgi")) {
- /* gotcha */
- return $php_path."/cgi/php-cgi";
+ /* Try sapi/cgi/php-cgi, for the case where php is not installed. */
+ $cgi_path = dirname($php, 3) . "/sapi/cgi/php-cgi";
+ if (is_executable($cgi_path)) {
+ return $cgi_path;
}
}
return false;