PHP code example of wyrihaximus / react-child-process-closure

1. Go to this page and download the library: Download wyrihaximus/react-child-process-closure 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/ */

    

wyrihaximus / react-child-process-closure example snippets


use React\EventLoop\Factory as EventLoopFactory;
use WyriHaximus\React\ChildProcess\Closure\ClosureChild;
use WyriHaximus\React\ChildProcess\Closure\MessageFactory;
use WyriHaximus\React\ChildProcess\Messenger\Factory as MessengerFactory;
use WyriHaximus\React\ChildProcess\Messenger\Messages\Payload;
use WyriHaximus\React\ChildProcess\Messenger\Messenger;

$loop = EventLoopFactory::create();

MessengerFactory::parentFromClass(ClosureChild::class, $loop)->then(function (Messenger $messenger) use ($loop) {
    $messenger->rpc(MessageFactory::rpc(function () {
        return resolve(['time' => time()]);
    })->done(function (Payload $payload) {
        echo 'Time in the child process: ', $payload['time'], PHP_EOL;
    });
});

$loop->run();