Skip to content

Commit 956dde0

Browse files
committed
Simplify and fix php-cgi detection
Make it work for installed PHP binaries.
1 parent f930978 commit 956dde0

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

sapi/cgi/tests/include.inc

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,21 @@ function get_cgi_path() /* {{{ */
2323
$php_path = $php;
2424
if (defined("PHP_WINDOWS_VERSION_MAJOR")) {
2525
/* On Windows it should be in the same dir as php.exe in most of the cases. */
26-
$php_path = dirname($php);
27-
28-
if (is_dir($php_path) && file_exists("$php_path/php-cgi.exe") && is_executable("$php_path/php-cgi.exe")) {
29-
return "$php_path/php-cgi.exe";
26+
$cgi_path = dirname($php) . "/php-cgi.exe";
27+
if (is_executable($cgi_path)) {
28+
return $cgi_path;
3029
}
3130
} else {
32-
for ($i = 0; $i < 2; $i++) {
33-
$slash_pos = strrpos($php_path, "/");
34-
if ($slash_pos) {
35-
$php_path = substr($php_path, 0, $slash_pos);
36-
} else {
37-
return FALSE;
38-
}
31+
/* Try in the same path as php, for the case where php is installed. */
32+
$cgi_path = dirname($php) . "/php-cgi";
33+
if (is_executable($cgi_path)) {
34+
return $cgi_path;
3935
}
4036

41-
if ($php_path && is_dir($php_path) && file_exists($php_path."/cgi/php-cgi") && is_executable($php_path."/cgi/php-cgi")) {
42-
/* gotcha */
43-
return $php_path."/cgi/php-cgi";
37+
/* Try sapi/cgi/php-cgi, for the case where php is not installed. */
38+
$cgi_path = dirname($php, 3) . "/sapi/cgi/php-cgi";
39+
if (is_executable($cgi_path)) {
40+
return $cgi_path;
4441
}
4542
}
4643
return false;

0 commit comments

Comments
 (0)