Skip to content

Commit ec5b469

Browse files
committedNov 23, 2015
php-fastcgi-client
php-fastcgi-client
1 parent bc83627 commit ec5b469

File tree

6 files changed

+786
-0
lines changed

6 files changed

+786
-0
lines changed
 

‎PHP-FastCGI-Client/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
vendor

‎PHP-FastCGI-Client/LICENSE

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2010-2014 Pierrick Charron
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy of
4+
this software and associated documentation files (the "Software"), to deal in
5+
the Software without restriction, including without limitation the rights to
6+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
7+
of the Software, and to permit persons to whom the Software is furnished to do
8+
so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in all
11+
copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19+
SOFTWARE.

‎PHP-FastCGI-Client/README

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
_________________________
2+
3+
PHP FastCGI Client README
4+
_________________________
5+
6+
7+
AUTHOR & CONTACT
8+
================
9+
10+
Charron Pierrick
11+
- pierrick@adoy.net
12+
13+
14+
DOCUMENTATION & DOWNLOAD
15+
========================
16+
17+
Latest version is available on github at :
18+
- http://github.com/adoy/PHP-FastCGI-Client/
19+
20+
Documentation can be found on :
21+
- http://github.com/adoy/PHP-FastCGI-Client/
22+
23+
24+
LICENSE
25+
=======
26+
27+
This Code is released under the MIT license.
28+
29+
For the full copyright and license information, please view the LICENSE
30+
file that was distributed with this source code.
31+
32+
How can I use it ?
33+
==================
34+
35+
require 'vendor/autoload.php';
36+
37+
use Adoy\FastCGI\Client;
38+
39+
// Existing socket, such as Lighttpd with mod_fastcgi:
40+
$client = new Client('unix:///path/to/php/socket', -1);
41+
// Fastcgi server, such as PHP-FPM:
42+
$client = new Client('localhost', '9000');
43+
$content = 'key=value';
44+
echo $client->request(
45+
array(
46+
'GATEWAY_INTERFACE' => 'FastCGI/1.0',
47+
'REQUEST_METHOD' => 'POST',
48+
'SCRIPT_FILENAME' => 'test.php',
49+
'SERVER_SOFTWARE' => 'php/fcgiclient',
50+
'REMOTE_ADDR' => '127.0.0.1',
51+
'REMOTE_PORT' => '9985',
52+
'SERVER_ADDR' => '127.0.0.1',
53+
'SERVER_PORT' => '80',
54+
'SERVER_NAME' => 'mag-tured',
55+
'SERVER_PROTOCOL' => 'HTTP/1.1',
56+
'CONTENT_TYPE' => 'application/x-www-form-urlencoded',
57+
'CONTENT_LENGTH' => strlen($content)
58+
),
59+
$content
60+
);
61+
62+
Command line tool
63+
=================
64+
65+
Run a call through a network socket:
66+
67+
./fcgiget.php localhost:9000/status
68+
69+
Run a call through a Unix Domain Socket
70+
71+
./fcgiget.php unix:/var/run/php-fpm/web.sock/status
72+
73+
This command line tool is provided for debuging purpose.

‎PHP-FastCGI-Client/composer.json

+15
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": "MIT",
6+
"authors": [
7+
{
8+
"name": "Pierrick Charron",
9+
"email": "pierrick@adoy.net"
10+
}
11+
],
12+
"autoload": {
13+
"psr-0": { "Adoy\\FastCGI\\": "src" }
14+
}
15+
}

‎PHP-FastCGI-Client/fcgiget.php

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
#!/usr/bin/env php
2+
<?php
3+
/*
4+
* This file is part of PHP-FastCGI-Client.
5+
*
6+
* (c) Pierrick Charron <pierrick@adoy.net>
7+
* Remi Collet <remi@famillecollet.com>
8+
*
9+
* For the full copyright and license information, please view the LICENSE
10+
* file that was distributed with this source code.
11+
*/
12+
require 'src/Adoy/FastCGI/Client.php';
13+
14+
use Adoy\FastCGI\Client;
15+
16+
/**
17+
* Simple command line script to test communication with a FastCGI server
18+
*
19+
* @author Pierrick Charron <pierrick@adoy.net>
20+
* @author Remi Collet <remi@famillecollet.com>
21+
* @version 1.0
22+
*/
23+
if (!isset($_SERVER['argc'])) {
24+
die("Command line only\n");
25+
}
26+
if ($_SERVER['argc']<2) {
27+
echo "Usage: ".$_SERVER['argv'][0]." URI\n\n";
28+
echo "Ex: ".$_SERVER['argv'][0]." localhost:9000/status\n";
29+
echo "Ex: ".$_SERVER['argv'][0]." unix:/var/run/php-fpm/web.sock/status\n";
30+
exit(1);
31+
}
32+
33+
if (preg_match('|^unix:(.*.sock)(/.*)$|', $_SERVER['argv'][1], $reg)) {
34+
$url = parse_url($reg[2]);
35+
$sock = $reg[1];
36+
if (!file_exists($sock)) {
37+
die("UDS $sock not found\n");
38+
} else if (!is_writable($sock)) {
39+
die("UDS $sock is not writable\n");
40+
}
41+
} else {
42+
$url = parse_url($_SERVER['argv'][1]);
43+
$sock = false;
44+
}
45+
if (!$url || !isset($url['path'])) {
46+
die("Malformed URI");
47+
}
48+
49+
$req = '/'.basename($url['path']);
50+
if (isset($url['query'])) {
51+
$uri = $req .'?'.$url['query'];
52+
} else {
53+
$url['query'] = '';
54+
$uri = $req;
55+
}
56+
if ($sock) {
57+
$client = new Client("unix://$sock", -1);
58+
echo "Call: $uri on UDS $sock\n\n";
59+
} else {
60+
$host = (isset($url['host']) ? $url['host'] : 'localhost');
61+
$port = (isset($url['port']) ? $url['port'] : 9000);
62+
$client = new Client($host, $port);
63+
echo "Call: $uri on $host:$port\n\n";
64+
}
65+
66+
$params = array(
67+
'GATEWAY_INTERFACE' => 'FastCGI/1.0',
68+
'REQUEST_METHOD' => 'GET',
69+
'SCRIPT_FILENAME' => $url['path'],
70+
'SCRIPT_NAME' => $req,
71+
'QUERY_STRING' => $url['query'],
72+
'REQUEST_URI' => $uri,
73+
'DOCUMENT_URI' => $req,
74+
'SERVER_SOFTWARE' => 'php/fcgiclient',
75+
'REMOTE_ADDR' => '127.0.0.1',
76+
'REMOTE_PORT' => '9985',
77+
'SERVER_ADDR' => '127.0.0.1',
78+
'SERVER_PORT' => '80',
79+
'SERVER_NAME' => php_uname('n'),
80+
'SERVER_PROTOCOL' => 'HTTP/1.1',
81+
'CONTENT_TYPE' => '',
82+
'CONTENT_LENGTH' => 0
83+
);
84+
//print_r($params);
85+
echo $client->request($params, false)."\n";
86+

‎PHP-FastCGI-Client/src/Adoy/FastCGI/Client.php

+592
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)
Please sign in to comment.