|
1 | | -#!/usr/bin/php |
| 1 | +#!/usr/bin/env php |
2 | 2 | <?php |
3 | 3 | /* |
4 | 4 | * This file is part of PHP-FastCGI-Client. |
|
24 | 24 | die("Command line only\n"); |
25 | 25 | } |
26 | 26 | if ($_SERVER['argc']<2) { |
27 | | - die("Usage: ".$_SERVER['argv'][0]." URI\n\nEx: ".$_SERVER['argv'][0]." localhost:9000/status\n"); |
| 27 | + echo "Usage: ".$_SERVER['argv'][0]." URI\n\n"; |
| 28 | + echo "Ex: ".$_SERVER['argv'][0]." localhost:9000/status\n"; |
| 29 | + echo "Ex: ".$_SERVER['argv'][0]." unix:/var/run/php-fpm/web.sock/status\n"; |
| 30 | + exit(1); |
28 | 31 | } |
29 | 32 |
|
30 | | -$url = parse_url($_SERVER['argv'][1]); |
| 33 | +if (preg_match('|^unix:(.*.sock)(/.*)$|', $_SERVER['argv'][1], $reg)) { |
| 34 | + $url = parse_url($reg[2]); |
| 35 | + $sock = $reg[1]; |
| 36 | + if (!file_exists($sock)) { |
| 37 | + die("UDS $sock not found\n"); |
| 38 | + } else if (!is_writable($sock)) { |
| 39 | + die("UDS $sock is not writable\n"); |
| 40 | + } |
| 41 | +} else { |
| 42 | + $url = parse_url($_SERVER['argv'][1]); |
| 43 | + $sock = false; |
| 44 | +} |
31 | 45 | if (!$url || !isset($url['path'])) { |
32 | 46 | die("Malformed URI"); |
33 | 47 | } |
|
39 | 53 | $url['query'] = ''; |
40 | 54 | $uri = $req; |
41 | 55 | } |
42 | | -$client = new Client( |
43 | | - (isset($url['host']) ? $url['host'] : 'localhost'), |
44 | | - (isset($url['port']) ? $url['port'] : 9000)); |
| 56 | +if ($sock) { |
| 57 | + $client = new Client("unix://$sock", -1); |
| 58 | + echo "Call: $uri on UDS $sock\n\n"; |
| 59 | +} else { |
| 60 | + $host = (isset($url['host']) ? $url['host'] : 'localhost'); |
| 61 | + $port = (isset($url['port']) ? $url['port'] : 9000); |
| 62 | + $client = new Client($host, $port); |
| 63 | + echo "Call: $uri on $host:$port\n\n"; |
| 64 | +} |
45 | 65 |
|
46 | 66 | $params = array( |
47 | 67 | 'GATEWAY_INTERFACE' => 'FastCGI/1.0', |
|
62 | 82 | 'CONTENT_LENGTH' => 0 |
63 | 83 | ); |
64 | 84 | //print_r($params); |
65 | | -echo "Call: $uri\n\n"; |
66 | 85 | echo $client->request($params, false)."\n"; |
67 | 86 |
|
0 commit comments