├── .circleci └── config.yml ├── .gitignore ├── LICENSE ├── README.md ├── app.php ├── composer.json └── php-fpm-status /.circleci/config.yml: -------------------------------------------------------------------------------- 1 | jobs: 2 | build: 3 | docker: 4 | - image: composer 5 | - image: php:7-fpm 6 | command: [sh, -c, echo "pm.status_path=/status" >> /usr/local/etc/php-fpm.d/www.conf && php-fpm] 7 | 8 | working_directory: /app 9 | 10 | steps: 11 | - checkout 12 | - run: composer install --no-progress 13 | - run: php php-fpm-status --socket=tcp://localhost:9000 14 | - run: php php-fpm-status --socket=tcp://localhost:9000 --format=json 15 | - run: php php-fpm-status --socket=tcp://localhost:9000 --format=xml 16 | - run: php php-fpm-status --socket=tcp://localhost:9000 --format=html 17 | - run: php php-fpm-status --socket=tcp://localhost:9000 --full 18 | - run: php php-fpm-status --socket=tcp://localhost:9000 --format=json --full 19 | - run: php php-fpm-status --socket=tcp://localhost:9000 --format=xml --full 20 | - run: php php-fpm-status --socket=tcp://localhost:9000 --format=html --full 21 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | composer.lock 2 | /vendor 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Wizacha 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # php-fpm-status-cli 2 | 3 | Simple CLI to access PHP-FPM status page when the HTTP server is not configured to do so. 4 | 5 | [![CircleCI](https://circleci.com/gh/wizaplace/php-fpm-status-cli.svg?style=svg)](https://circleci.com/gh/wizaplace/php-fpm-status-cli) 6 | 7 | ## Install 8 | 9 | ``` 10 | $ composer require wizaplace/php-fpm-status-cli 11 | ``` 12 | 13 | ## Usage 14 | 15 | ``` 16 | $ php-fpm-status -h 17 | Usage: 18 | php-fpm-status [options] 19 | 20 | Options: 21 | --socket=SOCKET Unix socket or tcp address where php-fpm listens [default: "unix:///run/php/php7.1-fpm.sock"] 22 | --path=PATH The URI to view the FPM status page. If this value is not set, no URI will be recognized as a status page. [default: "/status"] 23 | --full Show full server status 24 | --format=FORMAT Output format for the status, txt by default, [html, json, xml] available 25 | -h, --help Display this help message 26 | -q, --quiet Do not output any message 27 | -V, --version Display this application version 28 | --ansi Force ANSI output 29 | --no-ansi Disable ANSI output 30 | -n, --no-interaction Do not ask any interactive question 31 | -v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug 32 | 33 | Help: 34 | Get PHP-FPM status 35 | ``` 36 | 37 | The `socket` can be `unix:///path/to/socket` for a UNIX socket or `tcp://127.0.0.1:9000` for a TCP address. 38 | 39 | The `path` is the `pm.status_path` configuration option in the main FPM config or in the pool. 40 | 41 | ## Output 42 | 43 | ```shell 44 | $ php-fpm-status 45 | pool: www 46 | process manager: dynamic 47 | start time: 18/Oct/2017:13:48:20 +0000 48 | start since: 6 49 | accepted conn: 1 50 | listen queue: 0 51 | max listen queue: 0 52 | listen queue len: 128 53 | idle processes: 1 54 | active processes: 1 55 | total processes: 2 56 | max active processes: 1 57 | max children reached: 0 58 | slow requests: 0 59 | ``` 60 | 61 | Use the `--full` option to retrieve more information. 62 | -------------------------------------------------------------------------------- /app.php: -------------------------------------------------------------------------------- 1 | command('run [--socket=] [--path=] [--full] [--format=] [-i|--header]', function (OutputInterface $output, $socket, $path, $full, $format, $header) { 7 | $query = []; 8 | 9 | if ($full) { 10 | $query[] = 'full'; 11 | } 12 | 13 | if (null !== $format) { 14 | if (!in_array($format, ['html', 'xml', 'json'])) { 15 | throw new \InvalidArgumentException(sprintf('Format "%s" does not exist', $format)); 16 | } 17 | 18 | $query[] = $format; 19 | } 20 | 21 | $fastcgi = new Hoa\Fastcgi\Responder( 22 | new Hoa\Socket\Client($socket) 23 | ); 24 | 25 | $stderr = $output->getErrorOutput(); 26 | 27 | try { 28 | $response = $fastcgi->send([ 29 | 'REQUEST_METHOD' => 'GET', 30 | 'SCRIPT_NAME' => $path, 31 | 'SCRIPT_FILENAME' => $path, 32 | 'QUERY_STRING' => implode('&', $query), 33 | ]); 34 | } catch (\Exception $e) { 35 | $stderr->writeln('Tried sending to PHP-FPM but got the following error: ' . $e->getMessage()); 36 | 37 | return 1; 38 | } 39 | 40 | $headers = $fastcgi->getResponseHeaders(); 41 | 42 | if ($header) { 43 | $output->writeln(formatHeaders($headers)."\n"); 44 | } 45 | 46 | if (isset($headers['status'])) { 47 | $stderr->writeln('PHP-FPM returns status: '.$headers['status'].''); 48 | 49 | return 1; 50 | } 51 | 52 | $output->write($response, false, OutputInterface::OUTPUT_RAW); 53 | })->defaults([ 54 | 'socket' => 'unix:///run/php/php7.1-fpm.sock', 55 | 'path' => '/status', 56 | ])->descriptions('Get PHP-FPM status', [ 57 | '--socket' => 'Unix socket or tcp address where php-fpm listens', 58 | '--path' => 'The URI to view the FPM status page. If this value is not set, no URI will be recognized as a status page.', 59 | '--full' => 'Show full server status', 60 | '--format' => 'Output format for the status, txt by default, [html, json, xml] available', 61 | '--header' => 'Output fastcgi headers', 62 | ]); 63 | $app->setDefaultCommand('run'); 64 | 65 | return $app; 66 | 67 | function formatHeaders($headers) 68 | { 69 | return implode("\n", array_map(function ($key, $value) { 70 | return "{$key}: {$value}"; 71 | }, array_keys($headers), array_values($headers))); 72 | } 73 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "wizaplace/php-fpm-status-cli", 3 | "description": "PHP-FPM status-page CLI", 4 | "license": "MIT", 5 | "require": { 6 | "mnapoli/silly": "^1.6", 7 | "hoa/fastcgi": "@dev", 8 | "hoa/socket": "~1.0" 9 | }, 10 | "bin": [ 11 | "php-fpm-status" 12 | ] 13 | } 14 | -------------------------------------------------------------------------------- /php-fpm-status: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env php 2 | run(); 27 | --------------------------------------------------------------------------------