Skip to content

Commit 6b88c12

Browse files
committed
Merge pull request #1 from remicollet/master
Fix readPacket + test script
2 parents fb06250 + a6d2952 commit 6b88c12

File tree

2 files changed

+59
-4
lines changed

2 files changed

+59
-4
lines changed

fastcgi.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,10 +241,16 @@ private function readPacket()
241241
{
242242
if ($packet = fread($this->_sock, self::HEADER_LEN)) {
243243
$resp = $this->decodePacketHeader($packet);
244-
if ($len = $resp['contentLength'] + $resp['paddingLength']) {
245-
$resp['content'] = substr(fread($this->_sock, $len), 0, $resp['contentLength']);
246-
} else {
247-
$resp['content'] = '';
244+
$resp['content'] = '';
245+
if ($resp['contentLength']) {
246+
$len = $resp['contentLength'];
247+
while ($len && $buf=fread($this->_sock, $len)) {
248+
$len -= strlen($buf);
249+
$resp['content'] .= $buf;
250+
}
251+
}
252+
if ($resp['paddingLength']) {
253+
$buf=fread($this->_sock, $resp['paddingLength']);
248254
}
249255
return $resp;
250256
} else {

fcgiget.php

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/usr/bin/php
2+
<?php
3+
require('fastcgi.php');
4+
5+
if (!isset($_SERVER['argc'])) {
6+
die("Command line only\n");
7+
}
8+
if ($_SERVER['argc']<2) {
9+
die("Usage: ".$_SERVER['argv'][0]." URI\n\nEx: ".$_SERVER['argv'][0]." localhost:9000/status\n");
10+
}
11+
12+
$url = parse_url($_SERVER['argv'][1]);
13+
if (!$url || !isset($url['path'])) {
14+
die("Malformed URI");
15+
}
16+
17+
$req = '/'.basename($url['path']);
18+
if (isset($url['query'])) {
19+
$uri = $req .'?'.$url['query'];
20+
} else {
21+
$url['query'] = '';
22+
$uri = $req;
23+
}
24+
$client = new FCGIClient(
25+
(isset($url['host']) ? $url['host'] : 'localhost'),
26+
(isset($url['port']) ? $url['port'] : 9000));
27+
28+
$params = array(
29+
'GATEWAY_INTERFACE' => 'FastCGI/1.0',
30+
'REQUEST_METHOD' => 'GET',
31+
'SCRIPT_FILENAME' => $url['path'],
32+
'SCRIPT_NAME' => $req,
33+
'QUERY_STRING' => $url['query'],
34+
'REQUEST_URI' => $uri,
35+
'DOCUMENT_URI' => $req,
36+
'SERVER_SOFTWARE' => 'php/fcgiclient',
37+
'REMOTE_ADDR' => '127.0.0.1',
38+
'REMOTE_PORT' => '9985',
39+
'SERVER_ADDR' => '127.0.0.1',
40+
'SERVER_PORT' => '80',
41+
'SERVER_NAME' => php_uname('n'),
42+
'SERVER_PROTOCOL' => 'HTTP/1.1',
43+
'CONTENT_TYPE' => '',
44+
'CONTENT_LENGTH' => 0
45+
);
46+
//print_r($params);
47+
echo "Call: $uri\n\n";
48+
echo $client->request($params, false)."\n";
49+

0 commit comments

Comments
 (0)