Skip to content

Commit bb0e722

Browse files
committed
Merge pull request #3 from igorw/adjust
Composer, namespacing, PSR-0 autoloading
2 parents e7a7751 + 4dbf2a7 commit bb0e722

File tree

5 files changed

+47
-25
lines changed

5 files changed

+47
-25
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
vendor

README

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
_________________________
2-
2+
33
PHP FastCGI Client README
44
_________________________
5-
5+
66

77
AUTHOR & CONTACT
88
================
99

1010
Charron Pierrick
1111
- pierrick@webstart.fr
1212

13-
13+
1414
DOCUMENTATION & DOWNLOAD
1515
========================
1616

1717
Latest version is available on github at :
1818
- http://github.com/adoy/PHP-FastCGI-Client/
1919

20-
Documentation can be found on :
20+
Documentation can be found on :
2121
- http://github.com/adoy/PHP-FastCGI-Client/
2222

2323

@@ -28,13 +28,13 @@ This Code is released under the GNU LGPL
2828

2929
Please do not change the header of the file(s).
3030

31-
This library is free software; you can redistribute it and/or modify it
32-
under the terms of the GNU Lesser General Public License as published
33-
by the Free Software Foundation; either version 2 of the License, or
31+
This library is free software; you can redistribute it and/or modify it
32+
under the terms of the GNU Lesser General Public License as published
33+
by the Free Software Foundation; either version 2 of the License, or
3434
(at your option) any later version.
3535

36-
This library is distributed in the hope that it will be useful, but
37-
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
36+
This library is distributed in the hope that it will be useful, but
37+
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
3838
or FITNESS FOR A PARTICULAR PURPOSE.
3939

4040
See the GNU Lesser General Public License for more details.
@@ -43,12 +43,14 @@ See the GNU Lesser General Public License for more details.
4343
How can I use it ?
4444
==================
4545

46-
require('fastcgi.php');
46+
require 'vendor/autoload.php';
47+
48+
use Adoy\FastCGI\Client;
4749

48-
$client = new FCGIClient('localhost', '9000');
50+
$client = new Client('localhost', '9000');
4951
$content = 'key=value';
5052
echo $client->request(
51-
array(
53+
array(
5254
'GATEWAY_INTERFACE' => 'FastCGI/1.0',
5355
'REQUEST_METHOD' => 'POST',
5456
'SCRIPT_FILENAME' => 'test.php',

composer.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "adoy/fastcgi-client",
3+
"description": "Client for communication with a FastCGI (FCGI) application using the FastCGI protocol.",
4+
"keywords": ["fastcgi"],
5+
"license": "LGPL-2.1",
6+
"authors": [
7+
{
8+
"name": "Pierrick Charron",
9+
"email": "pierrick@php.net"
10+
}
11+
],
12+
"autoload": {
13+
"psr-0": { "Adoy\\FastCGI\\": "src" }
14+
}
15+
}

fcgiget.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,17 @@
1515
* See the GNU Lesser General Public License for more details.
1616
*/
1717

18+
require 'src/Adoy/FastCGI/Client.php';
19+
20+
use Adoy\FastCGI\Client;
21+
1822
/**
1923
* Simple command line script to test communication with a FastCGI server
2024
*
2125
* @author Pierrick Charron <pierrick@webstart.fr>
2226
* @author Remi Collet <remi@famillecollet.com>
2327
* @version 1.0
2428
*/
25-
require('fastcgi.php');
26-
2729
if (!isset($_SERVER['argc'])) {
2830
die("Command line only\n");
2931
}
@@ -43,11 +45,11 @@
4345
$url['query'] = '';
4446
$uri = $req;
4547
}
46-
$client = new FCGIClient(
47-
(isset($url['host']) ? $url['host'] : 'localhost'),
48+
$client = new Client(
49+
(isset($url['host']) ? $url['host'] : 'localhost'),
4850
(isset($url['port']) ? $url['port'] : 9000));
4951

50-
$params = array(
52+
$params = array(
5153
'GATEWAY_INTERFACE' => 'FastCGI/1.0',
5254
'REQUEST_METHOD' => 'GET',
5355
'SCRIPT_FILENAME' => $url['path'],

fastcgi.php renamed to src/Adoy/FastCGI/Client.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@
1414
* See the GNU Lesser General Public License for more details.
1515
*/
1616

17+
namespace Adoy\FastCGI;
18+
1719
/**
1820
* Handles communication with a FastCGI application
1921
*
20-
* @author Pierrick Charron <pierrick@webstart.fr>
22+
* @author Pierrick Charron <pierrick@webstart.fr>
2123
* @version 1.0
2224
*/
23-
class FCGIClient
25+
class Client
2426
{
2527
const VERSION_1 = 1;
2628

@@ -120,7 +122,7 @@ private function connect()
120122
if (!$this->_sock) {
121123
$this->_sock = fsockopen($this->_host, $this->_port, $errno, $errstr, 5);
122124
if (!$this->_sock) {
123-
throw new Exception('Unable to connect to FastCGI application');
125+
throw new \Exception('Unable to connect to FastCGI application');
124126
}
125127
}
126128
}
@@ -278,7 +280,7 @@ public function getValues(array $requestedInfo)
278280
if ($resp['type'] == self::GET_VALUES_RESULT) {
279281
return $this->readNvpair($resp['content'], $resp['length']);
280282
} else {
281-
throw new Exception('Unexpected response type, expecting GET_VALUES_RESULT');
283+
throw new \Exception('Unexpected response type, expecting GET_VALUES_RESULT');
282284
}
283285
}
284286

@@ -320,18 +322,18 @@ public function request(array $params, $stdin)
320322
} while ($resp && $resp['type'] != self::END_REQUEST);
321323

322324
if (!is_array($resp)) {
323-
throw new Exception('Bad request');
325+
throw new \Exception('Bad request');
324326
}
325327

326328
switch (ord($resp['content']{4})) {
327329
case self::CANT_MPX_CONN:
328-
throw new Exception('This app can\'t multiplex [CANT_MPX_CONN]');
330+
throw new \Exception('This app can\'t multiplex [CANT_MPX_CONN]');
329331
break;
330332
case self::OVERLOADED:
331-
throw new Exception('New request rejected; too busy [OVERLOADED]');
333+
throw new \Exception('New request rejected; too busy [OVERLOADED]');
332334
break;
333335
case self::UNKNOWN_ROLE:
334-
throw new Exception('Role value not known [UNKNOWN_ROLE]');
336+
throw new \Exception('Role value not known [UNKNOWN_ROLE]');
335337
break;
336338
case self::REQUEST_COMPLETE:
337339
return $response;

0 commit comments

Comments
 (0)