|
| 1 | +#!/usr/bin/php |
| 2 | +<?php |
| 3 | +/* |
| 4 | + * This file is part of PHP-FastCGI-Client. |
| 5 | + * |
| 6 | + * (c) Pierrick Charron <pierrick@adoy.net> |
| 7 | + * Remi Collet <remi@famillecollet.com> |
| 8 | + * |
| 9 | + * For the full copyright and license information, please view the LICENSE |
| 10 | + * file that was distributed with this source code. |
| 11 | + */ |
| 12 | +require 'src/Adoy/FastCGI/Client.php'; |
| 13 | + |
| 14 | +use Adoy\FastCGI\Client; |
| 15 | + |
| 16 | +/** |
| 17 | + * Simple command line script to test communication with a FastCGI server |
| 18 | + * |
| 19 | + * @author Pierrick Charron <pierrick@adoy.net> |
| 20 | + * @author Remi Collet <remi@famillecollet.com> |
| 21 | + * @version 1.0 |
| 22 | + */ |
| 23 | +if (!isset($_SERVER['argc'])) { |
| 24 | + die("Command line only\n"); |
| 25 | +} |
| 26 | +if ($_SERVER['argc']<2) { |
| 27 | + die("Usage: ".$_SERVER['argv'][0]." URI\n\nEx: ".$_SERVER['argv'][0]." localhost:9000/status\n"); |
| 28 | +} |
| 29 | + |
| 30 | +$url = parse_url($_SERVER['argv'][1]); |
| 31 | +if (!$url || !isset($url['path'])) { |
| 32 | + die("Malformed URI"); |
| 33 | +} |
| 34 | + |
| 35 | +$req = '/'.basename($url['path']); |
| 36 | +if (isset($url['query'])) { |
| 37 | + $uri = $req .'?'.$url['query']; |
| 38 | +} else { |
| 39 | + $url['query'] = ''; |
| 40 | + $uri = $req; |
| 41 | +} |
| 42 | +$client = new Client( |
| 43 | + (isset($url['host']) ? $url['host'] : 'localhost'), |
| 44 | + (isset($url['port']) ? $url['port'] : 9000)); |
| 45 | + |
| 46 | +$params = array( |
| 47 | + 'GATEWAY_INTERFACE' => 'FastCGI/1.0', |
| 48 | + 'REQUEST_METHOD' => 'GET', |
| 49 | + 'SCRIPT_FILENAME' => $url['path'], |
| 50 | + 'SCRIPT_NAME' => $req, |
| 51 | + 'QUERY_STRING' => $url['query'], |
| 52 | + 'REQUEST_URI' => $uri, |
| 53 | + 'DOCUMENT_URI' => $req, |
| 54 | + 'SERVER_SOFTWARE' => 'php/fcgiclient', |
| 55 | + 'REMOTE_ADDR' => '127.0.0.1', |
| 56 | + 'REMOTE_PORT' => '9985', |
| 57 | + 'SERVER_ADDR' => '127.0.0.1', |
| 58 | + 'SERVER_PORT' => '80', |
| 59 | + 'SERVER_NAME' => php_uname('n'), |
| 60 | + 'SERVER_PROTOCOL' => 'HTTP/1.1', |
| 61 | + 'CONTENT_TYPE' => '', |
| 62 | + 'CONTENT_LENGTH' => 0 |
| 63 | +); |
| 64 | +echo $client->request($params, false)."\n"; |
| 65 | + |
0 commit comments