Skip to content

A cross-platform library to run a script or command in background process without waitting for process finish.What else, it can simple manage process such as get running status or stop it.

Notifications You must be signed in to change notification settings

jarlon/php-nohup

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

suport these system:

  • Windows
  • Linux
  • Mac osx

Document Language

Installation

Install via composer:

compoer require dgr/nohup

Usage

Run a script background

Look, so easy!

use dgr\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 dgr\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 dgr\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.

Author

大官人

About

A cross-platform library to run a script or command in background process without waitting for process finish.What else, it can simple manage process such as get running status or stop it.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%