Skip to content

Commit c332dfc

Browse files
committed
handle connection viz UDS in command line tool
1 parent eca6c65 commit c332dfc

File tree

2 files changed

+38
-7
lines changed

2 files changed

+38
-7
lines changed

README

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,15 @@ echo $client->request(
5959
$content
6060
);
6161

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.

fcgiget.php

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/php
1+
#!/usr/bin/env php
22
<?php
33
/*
44
* This file is part of PHP-FastCGI-Client.
@@ -24,10 +24,24 @@
2424
die("Command line only\n");
2525
}
2626
if ($_SERVER['argc']<2) {
27-
die("Usage: ".$_SERVER['argv'][0]." URI\n\nEx: ".$_SERVER['argv'][0]." localhost:9000/status\n");
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);
2831
}
2932

30-
$url = parse_url($_SERVER['argv'][1]);
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+
}
3145
if (!$url || !isset($url['path'])) {
3246
die("Malformed URI");
3347
}
@@ -39,9 +53,15 @@
3953
$url['query'] = '';
4054
$uri = $req;
4155
}
42-
$client = new Client(
43-
(isset($url['host']) ? $url['host'] : 'localhost'),
44-
(isset($url['port']) ? $url['port'] : 9000));
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+
}
4565

4666
$params = array(
4767
'GATEWAY_INTERFACE' => 'FastCGI/1.0',
@@ -62,6 +82,5 @@
6282
'CONTENT_LENGTH' => 0
6383
);
6484
//print_r($params);
65-
echo "Call: $uri\n\n";
6685
echo $client->request($params, false)."\n";
6786

0 commit comments

Comments
 (0)