Skip to content

Commit

Permalink
Simplify and fix php-cgi detection
Browse files Browse the repository at this point in the history
Make it work for installed PHP binaries.
  • Loading branch information
nikic committed Jun 26, 2020
1 parent f930978 commit 956dde0
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions sapi/cgi/tests/include.inc
Expand Up @@ -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;
Expand Down

0 comments on commit 956dde0

Please sign in to comment.