PHP code example of cocur / background-process

1. Go to this page and download the library: Download cocur/background-process library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

cocur / background-process example snippets


use Cocur\BackgroundProcess\BackgroundProcess;

$process = new BackgroundProcess('sleep 5');
$process->run();

use Cocur\BackgroundProcess\BackgroundProcess;

$process = new BackgroundProcess('sleep 5');
$process->run();

echo sprintf('Crunching numbers in process %d', $process->getPid());
while ($process->isRunning()) {
    echo '.';
    sleep(1);
}
echo "\nDone.\n";

// ...
if ($process->isRunning()) {
    $process->stop();
}

use Cocur\BackgroundProcess\BackgroundProcess;

$process = BackgroundProcess::createFromPID($pid);
$process->isRunning(); // -> true
$process->stop();      // -> true