PHP code example of rcalicdan / process-killer

1. Go to this page and download the library: Download rcalicdan/process-killer 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/ */

    

rcalicdan / process-killer example snippets




declare(strict_types=1);

cessKiller;

// Spawning a background process
$process = proc_open('php long_running_task.php', [], $pipes);
$status = proc_get_status($process);
$pid = $status['pid'];

// ... some asynchronous execution ...

// Forcefully terminate the process and all of its descendants
ProcessKiller::killTreesAsync([$pid]);

// Under the hood on Windows:
$cmd = "cmd /c start /B taskkill /F /T /PID {$pid}";