From: Nikita Popov Date: Fri, 26 Jun 2020 10:46:04 +0000 (+0200) Subject: Simplify and fix php-cgi detection X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=956dde0bc08ee5fccbaa89545ca74ecb99bc0310;p=php Simplify and fix php-cgi detection Make it work for installed PHP binaries. --- diff --git a/sapi/cgi/tests/include.inc b/sapi/cgi/tests/include.inc index cd9236f116..de526723df 100644 --- a/sapi/cgi/tests/include.inc +++ b/sapi/cgi/tests/include.inc @@ -23,24 +23,21 @@ function get_cgi_path() /* {{{ */ $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;