PHP code example of christiaan / stream-process

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

    

christiaan / stream-process example snippets


$loop = \React\EventLoop\Factory::create();

$child = new StreamProcess('php someWorkerProcess.php');

$loop->addReadStream($child->getReadStream(), function($stream) {
        $data = fgets($stream);
        fwrite(STDOUT, $data);
    });

$loop->addPeriodicTimer(1, function() {
        pcntl_signal_dispatch();
    });


pcntl_signal(SIGTERM, function() use($loop) {
        $loop->stop();
        // Cleanup before closing
        exit(0);
    });


fwrite($child->getWriteStream(), 'start');
$loop->run();