-
Notifications
You must be signed in to change notification settings - Fork 61
/
fcgiget.php
executable file
·86 lines (80 loc) · 2.36 KB
/
fcgiget.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/env php
<?php
/*
* This file is part of PHP-FastCGI-Client.
*
* (c) Pierrick Charron <[email protected]>
* Remi Collet <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
require 'src/Adoy/FastCGI/Client.php';
use Adoy\FastCGI\Client;
/**
* Simple command line script to test communication with a FastCGI server
*
* @author Pierrick Charron <[email protected]>
* @author Remi Collet <[email protected]>
* @version 1.0
*/
if (!isset($_SERVER['argc'])) {
die("Command line only\n");
}
if ($_SERVER['argc']<2) {
echo "Usage: ".$_SERVER['argv'][0]." URI\n\n";
echo "Ex: ".$_SERVER['argv'][0]." localhost:9000/status\n";
echo "Ex: ".$_SERVER['argv'][0]." unix:/var/run/php-fpm/web.sock/status\n";
exit(1);
}
if (preg_match('|^unix:(.*.sock)(/.*)$|', $_SERVER['argv'][1], $reg)) {
$url = parse_url($reg[2]);
$sock = $reg[1];
if (!file_exists($sock)) {
die("UDS $sock not found\n");
} else if (!is_writable($sock)) {
die("UDS $sock is not writable\n");
}
} else {
$url = parse_url($_SERVER['argv'][1]);
$sock = false;
}
if (!$url || !isset($url['path'])) {
die("Malformed URI");
}
$req = '/'.basename($url['path']);
if (isset($url['query'])) {
$uri = $req .'?'.$url['query'];
} else {
$url['query'] = '';
$uri = $req;
}
if ($sock) {
$client = new Client("unix://$sock", -1);
echo "Call: $uri on UDS $sock\n\n";
} else {
$host = (isset($url['host']) ? $url['host'] : 'localhost');
$port = (isset($url['port']) ? $url['port'] : 9000);
$client = new Client($host, $port);
echo "Call: $uri on $host:$port\n\n";
}
$params = array(
'GATEWAY_INTERFACE' => 'FastCGI/1.0',
'REQUEST_METHOD' => 'GET',
'SCRIPT_FILENAME' => $url['path'],
'SCRIPT_NAME' => $req,
'QUERY_STRING' => $url['query'],
'REQUEST_URI' => $uri,
'DOCUMENT_URI' => $req,
'SERVER_SOFTWARE' => 'php/fcgiclient',
'REMOTE_ADDR' => '127.0.0.1',
'REMOTE_PORT' => '9985',
'SERVER_ADDR' => '127.0.0.1',
'SERVER_PORT' => '80',
'SERVER_NAME' => php_uname('n'),
'SERVER_PROTOCOL' => 'HTTP/1.1',
'CONTENT_TYPE' => '',
'CONTENT_LENGTH' => 0
);
//print_r($params);
echo $client->request($params, false)."\n";