PHP code example of tetreum / process-monitor

1. Go to this page and download the library: Download tetreum/process-monitor library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

tetreum / process-monitor example snippets


use ProcessMonitor\ProcessMonitor;

$monitor = new ProcessMonitor();
$process = $monitor->search("apache");
    
if (!$process) {
    exit;
}
    echo "Apache (PID: " . $process->pid . ") is using " . $process->cpu . "% CPU and " . $process->ram . " RAM";

use ProcessMonitor\ProcessMonitor;

$monitor = new ProcessMonitor();
$process = $monitor->search("rust-server");

if (!$process) {
    exit;
}
    
if ($process->defunct) {
    $process->kill();
    // or you can just kill it's childs
    // $process->killChilds();
}

use ProcessMonitor\ProcessMonitor;

$monitor = new ProcessMonitor();
$processList = $monitor->searchMultiple("rust-server|nginx");

use ProcessMonitor\ProcessMonitor;

$monitor = new ProcessMonitor();
$result = $monitor->searchMultiple("rust-server|nginx", true);

// $result->processes contains the process list
// $result->summary:
// $result->summary["cpu"] // the most cpu consuming process
// $result->summary["defunct"] // returns any defunct process
/*
    [summary] => Array
        (
            [cpu] => ProcessMonitor\Process Object
                (
                    [user] => root
                    [pid] => 1230
                    [cpu] => 5
                    [ram] => 0.1
                    [vsz] => 15624
                    [rss] => 1412
                    [tty] => ?
                    [stat] => Ss
                    [start] => Apr13
                    [time] => 0:00
                    [command] => nginx: master process /usr/sbin/nginx
                    [defunct] =>
                    [debug:protected] =>
                )

            [defunct] =>
        )
*/

[PHP_COM_DOTNET]
extension=php_com_dotnet.dll