diff --git a/fcgiget.php b/fcgiget.php index baabc12..051ea0a 100755 --- a/fcgiget.php +++ b/fcgiget.php @@ -23,15 +23,23 @@ if (!isset($_SERVER['argc'])) { die("Command line only\n"); } -if ($_SERVER['argc']<2) { + +function print_usage_and_exit() { 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"; + 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]); +if ($_SERVER['argc']<2) { + print_usage_and_exit(); +} + +if (preg_match('|^unix:(.*)$|', $_SERVER['argv'][1], $reg)) { + if ($_SERVER['argc'] < 3) { + print_usage_and_exit(); + } + $url = parse_url($_SERVER['argv'][2]); $sock = $reg[1]; if (!file_exists($sock)) { die("UDS $sock not found\n"); @@ -46,7 +54,7 @@ die("Malformed URI"); } -$req = '/'.basename($url['path']); +$req = $url['path']; if (isset($url['query'])) { $uri = $req .'?'.$url['query']; } else {