diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..22d0d82 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +vendor diff --git a/README b/README index 4dcd4b0..44f8a5d 100644 --- a/README +++ b/README @@ -1,8 +1,8 @@ _________________________ - + PHP FastCGI Client README _________________________ - + AUTHOR & CONTACT ================ @@ -10,14 +10,14 @@ AUTHOR & CONTACT Charron Pierrick - pierrick@webstart.fr - + DOCUMENTATION & DOWNLOAD ======================== Latest version is available on github at : - http://github.com/adoy/PHP-FastCGI-Client/ -Documentation can be found on : +Documentation can be found on : - http://github.com/adoy/PHP-FastCGI-Client/ @@ -28,13 +28,13 @@ This Code is released under the GNU LGPL Please do not change the header of the file(s). -This library is free software; you can redistribute it and/or modify it -under the terms of the GNU Lesser General Public License as published -by the Free Software Foundation; either version 2 of the License, or +This library is free software; you can redistribute it and/or modify it +under the terms of the GNU Lesser General Public License as published +by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. -This library is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +This library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. @@ -43,12 +43,14 @@ See the GNU Lesser General Public License for more details. How can I use it ? ================== -require('fastcgi.php'); +require 'vendor/autoload.php'; + +use Adoy\FastCGI\Client; -$client = new FCGIClient('localhost', '9000'); +$client = new Client('localhost', '9000'); $content = 'key=value'; echo $client->request( - array( + array( 'GATEWAY_INTERFACE' => 'FastCGI/1.0', 'REQUEST_METHOD' => 'POST', 'SCRIPT_FILENAME' => 'test.php', diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..f61ecc7 --- /dev/null +++ b/composer.json @@ -0,0 +1,15 @@ +{ + "name": "adoy/fastcgi-client", + "description": "Client for communication with a FastCGI (FCGI) application using the FastCGI protocol.", + "keywords": ["fastcgi"], + "license": "LGPL-2.1", + "authors": [ + { + "name": "Pierrick Charron", + "email": "pierrick@php.net" + } + ], + "autoload": { + "psr-0": { "Adoy\\FastCGI\\": "src" } + } +} diff --git a/fcgiget.php b/fcgiget.php index 38762a0..19e0636 100755 --- a/fcgiget.php +++ b/fcgiget.php @@ -15,6 +15,10 @@ * See the GNU Lesser General Public License for more details. */ +require 'src/Adoy/FastCGI/Client.php'; + +use Adoy\FastCGI\Client; + /** * Simple command line script to test communication with a FastCGI server * @@ -22,8 +26,6 @@ * @author Remi Collet * @version 1.0 */ -require('fastcgi.php'); - if (!isset($_SERVER['argc'])) { die("Command line only\n"); } @@ -43,11 +45,11 @@ $url['query'] = ''; $uri = $req; } -$client = new FCGIClient( - (isset($url['host']) ? $url['host'] : 'localhost'), +$client = new Client( + (isset($url['host']) ? $url['host'] : 'localhost'), (isset($url['port']) ? $url['port'] : 9000)); -$params = array( +$params = array( 'GATEWAY_INTERFACE' => 'FastCGI/1.0', 'REQUEST_METHOD' => 'GET', 'SCRIPT_FILENAME' => $url['path'], diff --git a/fastcgi.php b/src/Adoy/FastCGI/Client.php similarity index 94% rename from fastcgi.php rename to src/Adoy/FastCGI/Client.php index 949f45e..bfb2d1b 100644 --- a/fastcgi.php +++ b/src/Adoy/FastCGI/Client.php @@ -14,13 +14,15 @@ * See the GNU Lesser General Public License for more details. */ +namespace Adoy\FastCGI; + /** * Handles communication with a FastCGI application * - * @author Pierrick Charron + * @author Pierrick Charron * @version 1.0 */ -class FCGIClient +class Client { const VERSION_1 = 1; @@ -120,7 +122,7 @@ private function connect() if (!$this->_sock) { $this->_sock = fsockopen($this->_host, $this->_port, $errno, $errstr, 5); if (!$this->_sock) { - throw new Exception('Unable to connect to FastCGI application'); + throw new \Exception('Unable to connect to FastCGI application'); } } } @@ -278,7 +280,7 @@ public function getValues(array $requestedInfo) if ($resp['type'] == self::GET_VALUES_RESULT) { return $this->readNvpair($resp['content'], $resp['length']); } else { - throw new Exception('Unexpected response type, expecting GET_VALUES_RESULT'); + throw new \Exception('Unexpected response type, expecting GET_VALUES_RESULT'); } } @@ -320,18 +322,18 @@ public function request(array $params, $stdin) } while ($resp && $resp['type'] != self::END_REQUEST); if (!is_array($resp)) { - throw new Exception('Bad request'); + throw new \Exception('Bad request'); } switch (ord($resp['content']{4})) { case self::CANT_MPX_CONN: - throw new Exception('This app can\'t multiplex [CANT_MPX_CONN]'); + throw new \Exception('This app can\'t multiplex [CANT_MPX_CONN]'); break; case self::OVERLOADED: - throw new Exception('New request rejected; too busy [OVERLOADED]'); + throw new \Exception('New request rejected; too busy [OVERLOADED]'); break; case self::UNKNOWN_ROLE: - throw new Exception('Role value not known [UNKNOWN_ROLE]'); + throw new \Exception('Role value not known [UNKNOWN_ROLE]'); break; case self::REQUEST_COMPLETE: return $response;