From c6ed666dcd4a4c2a93443c194d9c137a7fa99e89 Mon Sep 17 00:00:00 2001 From: Remi Collet Date: Tue, 13 Nov 2012 08:38:05 +0100 Subject: [PATCH 1/2] fix readPacket when buffered --- fastcgi.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/fastcgi.php b/fastcgi.php index 66a1c5f..949f45e 100644 --- a/fastcgi.php +++ b/fastcgi.php @@ -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 { From a6d295220adbf59be5149623a01b8286db1edd57 Mon Sep 17 00:00:00 2001 From: Remi Collet Date: Tue, 13 Nov 2012 08:39:51 +0100 Subject: [PATCH 2/2] Add command line test script --- fcgiget.php | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100755 fcgiget.php diff --git a/fcgiget.php b/fcgiget.php new file mode 100755 index 0000000..15496ec --- /dev/null +++ b/fcgiget.php @@ -0,0 +1,49 @@ +#!/usr/bin/php + '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"; +