lantongxue / php-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. It support Windows, Linux and Mac osx.
Installs: 10 497
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 2
Forks: 0
Open Issues: 1
This package is auto-updated.
Last update: 2025-05-07 13:00:32 UTC
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.
suport these system:
- Windows
- Linux
- Mac osx
Document Language
- English
- 简体中文
Installation
Install via composer:
compoer require lantongxue/nohup
Usage
Run a script background
Look, so easy!
use lantongxue\nohup\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 lantongxue\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 lantongxue\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.