Last active
November 6, 2017 15:50
-
-
Save akerouanton/d1abd15171f885cf084204d07a977fe1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require __DIR__ . '/vendor/autoload.php'; | |
use hollodotme\FastCGI\Client; | |
use hollodotme\FastCGI\SocketConnections\NetworkSocket; | |
use hollodotme\FastCGI\SocketConnections\UnixDomainSocket; | |
use hollodotme\FastCGI\Requests\GetRequest; | |
if ($argc < 3) { | |
echo "Usage: ${argv[0]} <server> <status-page> [<full>] [<format>]\n"; | |
echo "\n"; | |
echo "Parameters:\n"; | |
echo " <server>: IP and port (separated with :) or a valid path to a unix socket.\n"; | |
echo " <status-page>: URL of status page (as defined by \"pm.status_path\" parameter, in php-fpm pool config).\n"; | |
echo " <full>: Do you want to print the full page? (1 = true, anything else = false). Default: 0.\n"; | |
echo " <format>: Which format do you want? (text, json, html, xml). Default: text.\n"; | |
echo "\n"; | |
echo "Examples:\n"; | |
echo " ${argv[0]} 127.0.0.1:9000 /fpm_status\n"; | |
echo " ${argv[0]} /run/php/php7.0-fpm.sock /fpm_status\n"; | |
exit(1); | |
} | |
if (strpos($argv[1], ':') !== false) { | |
$connection = new NetworkSocket('127.0.0.1', 9000, 5000, 5000); | |
} elseif (file_exists($argv[1])) { | |
$connection = new UnixDomainSocket($argv[1]); | |
} else { | |
echo 'You should provide either a string with ip:port or a valid path to a unix socket.'; | |
exit(1); | |
} | |
$client = new Client($connection); | |
$full = ($argv[3] ?? '0') === '1'; | |
$format = $argv[4] ?? 'text'; | |
$query = []; | |
if ($full) { | |
$query[] = 'full'; | |
} | |
if ($format !== 'text') { | |
$query[] = $format; | |
} | |
$request = new GetRequest($argv[2], http_build_query($query)); | |
$request->setCustomVar('SCRIPT_NAME', $argv[2]); | |
$request->setCustomVar('QUERY_STRING', implode('&', $query)); | |
$response = $client->sendRequest($request); | |
echo $response->getBody(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment