]> granicus.if.org Git - php/commitdiff
Simplify and fix php-cgi detection
authorNikita Popov <nikita.ppv@gmail.com>
Fri, 26 Jun 2020 10:46:04 +0000 (12:46 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Fri, 26 Jun 2020 12:17:56 +0000 (14:17 +0200)
Make it work for installed PHP binaries.

sapi/cgi/tests/include.inc

index cd9236f11603482d1ccac03f31329f23c40df9e7..de526723df0f5971987451de037bab3f56fa29e1 100644 (file)
@@ -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;