From 353d996c9f21da123d01bc26bda36766e0ce73b9 Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Tue, 29 Sep 2015 16:47:57 +0200 Subject: [PATCH] tweak cgi binary search --- sapi/cgi/tests/include.inc | 29 +++++++++++++++++++---------- sapi/cgi/tests/skipif.inc | 4 ---- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/sapi/cgi/tests/include.inc b/sapi/cgi/tests/include.inc index 2d8ed8a2e3..dc98dc0f23 100644 --- a/sapi/cgi/tests/include.inc +++ b/sapi/cgi/tests/include.inc @@ -21,18 +21,27 @@ function get_cgi_path() /* {{{ */ if ($cli) { /* trying to guess ... */ $php_path = $php; - 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; + 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"; + } + } 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; + } } - } - 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"; + 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"; + } } return false; } diff --git a/sapi/cgi/tests/skipif.inc b/sapi/cgi/tests/skipif.inc index 9da8b7934d..d2cef23589 100644 --- a/sapi/cgi/tests/skipif.inc +++ b/sapi/cgi/tests/skipif.inc @@ -4,10 +4,6 @@ if (substr(php_sapi_name(), 0, 3) == "cgi") { exit; } -if (substr(PHP_OS, 0, 3) == 'WIN') { - die ("skip not for Windows"); -} - include dirname(__FILE__)."/include.inc"; if (!get_cgi_path()) { -- 2.50.1