mozartk/process-checker

Get list of running processes by process name, supports Windows and unix, macOS


Keywords
process, check, monitor
License
MIT

Documentation

process-checker

Build Status Coverage Status Coverage Status OJD

Now you can easily check the process information with php.

Installation

$ composer require mozartk/process-checker

Basic Usage

How to run

First, you need a config file in JSON format.

{  
  "processList":[  
    "php-fpm",
    "httpd"
  ],
  "outputMode":"array" //or json,yaml,ini
}

And run tue php script :

<?php
require "vendor/autoload.php";

use mozartk\ProcessChecker\ProcessChecker;

$processHandler = new ProcessChecker();
$processHandler->setConfigPath("config.json");
$data = $processHandler->run();

print_r($data); 

or you can try without a config file.

<?php
require_once "vendor/autoload.php";

use mozartk\ProcessChecker\ProcessChecker;

$processHandler = new ProcessChecker();
$processHandler->setOutputMode("array");
$processHandler->setProcessName(array("php", "httpd")); //Parameters must be an array.
$data = $processHandler->run();

print_r($data);

Results

Array
(
    [php-fpm] => Array
        (
            [0] => Array
                (
                    [name] => /bin/php-fpm
                    [name_w] =>
                    [cputime] => 0:22.74
                    [pid] => 65843
                    [running] => 1
                )

            [1] => Array
                (
                    [name] => /bin/php-fpm
                    [name_w] =>
                    [cputime] => 0:00.01
                    [pid] => 65846
                    [running] => 1
                )
                ...
        )
)

If you wants to get Yaml Results, change the outputMode value in config.json to yaml

php-fpm:
    -
        name: '/bin/php-fpm'
        name_w: false
        cputime: '0:18.63'
        pid: 65843
        running: true
    -
        name: '/bin/php-fpm'
        name_w: false
        cputime: '0:00.00'
        pid: 65846
        running: true
httpd:
    -
        name: '/bin/httpd -D FOREGROUND'
        name_w: false
        cputime: '0:44.38'
        pid: 94
        running: true
...

And you can get json results

{  
  "php-fpm":[  
    {  
      "name":"/bin/php-fpm",
      "name_w":false,
      "cputime":"0:18.61",
      "pid":12345,
      "running":true
    }
  ],
  "httpd":[  
    {  
      "name":"/bin/httpd -D FOREGROUND",
      "name_w":false,
      "cputime":"0:44.37",
      "pid":3360,
      "running":true
    },
    {  
      "name":"/bin/httpd -D FOREGROUND",
      "name_w":false,
      "cputime":"0:00.00",
      "pid":8801,
      "running":true
    }
  ]
}

And you can get ini type results too

[php-fpm(65843)]  
name = "/bin/php-fpm"  
name_w = 0  
cputime = "0:18.63"  
pid = 65843  
running = 1  
  
[php-fpm(65846)]  
name = "/bin/php-fpm"  
name_w = 0  
cputime = "0:00.01"  
pid = 65846  
running = 1   

License

Made by mozartk.
The MIT License (MIT). Please see License File for more information.