Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions fastcgi.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,16 @@ private function readPacket()
{
if ($packet = fread($this->_sock, self::HEADER_LEN)) {
$resp = $this->decodePacketHeader($packet);
if ($len = $resp['contentLength'] + $resp['paddingLength']) {
$resp['content'] = substr(fread($this->_sock, $len), 0, $resp['contentLength']);
} else {
$resp['content'] = '';
$resp['content'] = '';
if ($resp['contentLength']) {
$len = $resp['contentLength'];
while ($len && $buf=fread($this->_sock, $len)) {
$len -= strlen($buf);
$resp['content'] .= $buf;
}
}
if ($resp['paddingLength']) {
$buf=fread($this->_sock, $resp['paddingLength']);
}
return $resp;
} else {
Expand Down
49 changes: 49 additions & 0 deletions fcgiget.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/usr/bin/php
<?php
require('fastcgi.php');

if (!isset($_SERVER['argc'])) {
die("Command line only\n");
}
if ($_SERVER['argc']<2) {
die("Usage: ".$_SERVER['argv'][0]." URI\n\nEx: ".$_SERVER['argv'][0]." localhost:9000/status\n");
}

$url = parse_url($_SERVER['argv'][1]);
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;
}
$client = new FCGIClient(
(isset($url['host']) ? $url['host'] : 'localhost'),
(isset($url['port']) ? $url['port'] : 9000));

$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 "Call: $uri\n\n";
echo $client->request($params, false)."\n";