graftype / nohup
A library to run a command in the background, it will return the process's pid, and get it's is running status anytime in the another process, and can be stoped anytime.
1.0.12
2024-02-12 13:16 UTC
Requires
- phpseclib/phpseclib: ~3.0
Requires (Dev)
- phpunit/phpunit: ^5.7||^7.0||^8.0
README
A library to run a command in the background, it will return the process's pid, and get it's is running status anytime in the another process, and can be stoped anytime.
Navigation
Installation
Using composer:
composer require graftype/nohup
Usage
Run a script in background
use graftype\nohup; $process = Nohup::run('sleep 5');
It will be running in the background for 5 seconds.
But, it can be stoped any time:
//... $process->stop();
It stoped now!
Get the pid : $process->getPid()
, it will return the real pid in both window and *inx system.
Get it's running status with the function $process->isRunning()
:
use graftype\nohup\Nohup; $process = Nohup::run('sleep 5'); while ($process->isRunning()) { echo '.'; sleep(1); } echo "Done.\n";
output: .....Done.
Create process from known pid ($pid)
use graftype\nohup\Process; $process = Process::loadFromPid($pid); // or $process = new Process($pid); if ($process->isRunning()) { $process->stop(); }
Method:
Nohup::run($commandLine, $outputFile, $errorFile)
$commandLine
: string, the command will be run.$outputFile
: string, the file path where to save output content.$errlogFile
: string, the file path where to save error message.