xref: /PHP-5.4/sapi/cgi/tests/include.inc (revision 13dff748)
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		for ($i = 0; $i < 2; $i++) {
25			$slash_pos = strrpos($php_path, "/");
26			if ($slash_pos) {
27				$php_path = substr($php_path, 0, $slash_pos);
28			} else {
29				return FALSE;
30			}
31		}
32
33		if ($php_path && is_dir($php_path) && file_exists($php_path."/cgi/php-cgi") && is_executable($php_path."/cgi/php-cgi")) {
34			/* gotcha */
35			return $php_path."/cgi/php-cgi";
36		}
37		return false;
38	}
39	/* uhm? what's that then? */
40	return false;
41}
42/* }}} */
43
44function reset_env_vars() /* {{{ */
45{
46	putenv("REDIRECT_STATUS");
47	putenv("QUERY_STRING");
48	putenv("PATH_TRANSLATED");
49	putenv("SCRIPT_FILENAME");
50	putenv("SERVER_SOFTWARE");
51	putenv("SERVER_NAME");
52	putenv("GATEWAY_INTERFACE");
53	putenv("REQUEST_METHOD");
54}
55/* }}} */
56
57?>
58