<?php
 namespace TechOnline\Utils; class ShellUtil { public static function runRealtime($cmd) { echo "\n[ShellRun] $cmd\n"; if (($fp = popen($cmd, "r"))) { while (!feof($fp)) { echo fread($fp, 1024); flush(); } fclose($fp); } } public static function exec($command) { exec($command, $result, $ret); $result = join("\n", $result); return $result; } public static function processStartupSeconds($process) { $upTime = 0; $ret = shell_exec("ps -eo pid,etimes,cmd | grep '$process' | grep -v grep"); if (!empty($ret)) { $ret = trim($ret); $ps = preg_split('/\\s+/', $ret); if (!empty($ps[1])) { $upTime = intval($ps[1]); } } return $upTime; } public static function processCount($process) { $ret = shell_exec("ps -eo pid,etimes,cmd | grep '$process' | grep -v grep"); if (!empty($ret)) { $ret = trim($ret); return count(explode("\n", $ret)); } return 0; } }