PHP code example of tasoft / process

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

    

tasoft / process example snippets



use TASoft\Util\Process;

$process = new Process(function() {
    // Do stuff
});

// Now it will fork the process and call the callback function in separate process.
$process->run();

// Do other stuff in main process

// Wait until the child process has done
$process->wait();
// or kill the child process immediately.
$process->kill();


use TASoft\Util\Process;

$process = new Process(function(Process $childProcess) {
    $result = NULL;
    
    // Do hard stuff
    
    // Please don't import the parent process!
    $childProcess->sendData( $result );
});

$process->run();

// Do other stuff

$data = $process->receiveData();
echo $data;

$process->wait(); // or kill


use TASoft\Util\Process;

$process = new Process(function() use (&$process) {
    $result = NULL;
    // Do stuff
    $process->sendData( $result );
    
    // This is wrong and will not work because $process IS A COPY OF THE MAIN PROCESS!
});

...
$process->run()