PHP code example of jenner / react-multi-process
1. Go to this page and download the library: Download jenner/react-multi-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/ */
jenner / react-multi-process example snippets
$loop = React\EventLoop\Factory::create();
$server = stream_socket_server('tcp://127.0.0.1:4020');
stream_set_blocking($server, 0);
$loop->addReadStream($server, function ($server) use ($loop) {
$conn = stream_socket_accept($server);
$data = "pid:" . getmypid() . PHP_EOL;
$loop->addWriteStream($conn, function ($conn) use (&$data, $loop) {
$written = fwrite($conn, $data);
if ($written === strlen($data)) {
fclose($conn);
$loop->removeStream($conn);
} else {
$data = substr($data, 0, $written);
}
});
});
// the second param is the sub process count
$master = new \React\Multi\Master($loop, 20);
$master->start();