Awesome
jphp-process-ext
Process API for jphp, more advanced and powerful!
Features:
- Get process info (command, command line, args, etc).
- Kill processes and children processes.
- Get all running processes in OS.
- Get children and parent processes.
- Get processes by PID.
Requires
- Java 9+
- JPPM
How to install
jppm add jphp-process-ext
How to use?
- Get process handle of a process instance:
use php\lang\Process;
use process\ProcessHandle;
$process = new Process(['cmd', '/c', 'calc.exe']);
$processHandle = new ProcessHandle($process->start());
echo "PID: ", $processHandle->pid(), "\n";
echo "Info: ", print_r($processHandle->info(), true), "\n";
- How to destroy process?
$process = new Process(['cmd', '/c', 'calc.exe']);
$processHandle = new ProcessHandle($process->start());
$success = $processHandle->destroy();
- How to get children processes?
$processHandles = $processHandle->children();
foreach ($processHandles as $handle) {
var_dump($handle->info());
}
- How to get all process handles?
$allProcesses = ProcessHandle::allProcesses();
- How to get process handle by pid?
$pid = 13894;
$processHandler = ProcessHandle::ofPid($pid);
- How to get process handle of current process?
$processHandler = ProcessHandle::current();