mozartk/process-checker

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

v1.0.1 2018-05-16 13:44 UTC

This package is auto-updated.

Last update: 2020-10-09 20:32:59 UTC


README

Build Status 68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f7068702d762f6d6f7a6172746b2f70726f636573732d636865636b65722e737667 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 the 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.