xref: /PHP-8.1/sapi/cgi/tests/include.inc (revision 956dde0b)
1<?php
2
3function get_cgi_path() /* {{{ */
4{
5    $php = getenv("TEST_PHP_EXECUTABLE");
6
7    $cli = false;
8    $cgi = false;
9
10    if (file_exists($php) && is_executable($php)) {
11        $version = `$php -n -v`;
12        if (strstr($version, "(cli)")) {
13            /* that's cli */
14            $cli = true;
15        } else if (strpos($version, "(cgi")) {
16            /* that's cgi */
17            return $php;
18        }
19    }
20
21    if ($cli) {
22        /* trying to guess ... */
23        $php_path = $php;
24        if (defined("PHP_WINDOWS_VERSION_MAJOR")) {
25            /* On Windows it should be in the same dir as php.exe in most of the cases. */
26            $cgi_path = dirname($php) . "/php-cgi.exe";
27            if (is_executable($cgi_path)) {
28                return $cgi_path;
29            }
30        } else {
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;
35            }
36
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;
41            }
42        }
43        return false;
44    }
45    /* uhm? what's that then? */
46    return false;
47}
48/* }}} */
49
50function reset_env_vars() /* {{{ */
51{
52    putenv("REDIRECT_STATUS");
53    putenv("QUERY_STRING");
54    putenv("PATH_TRANSLATED");
55    putenv("SCRIPT_FILENAME");
56    putenv("SERVER_SOFTWARE");
57    putenv("SERVER_NAME");
58    putenv("GATEWAY_INTERFACE");
59    putenv("REQUEST_METHOD");
60}
61/* }}} */
62
63?>
64