https://github.com/white-poto/react-multi-process
multi process support to reactphp
https://github.com/white-poto/react-multi-process
multi-process reactphp sync
Last synced: about 1 month ago
JSON representation
multi process support to reactphp
- Host: GitHub
- URL: https://github.com/white-poto/react-multi-process
- Owner: white-poto
- License: mit
- Created: 2015-11-13T06:56:53.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2016-07-01T03:55:18.000Z (over 9 years ago)
- Last Synced: 2025-06-24T02:49:00.221Z (9 months ago)
- Topics: multi-process, reactphp, sync
- Language: PHP
- Size: 29.3 KB
- Stars: 7
- Watchers: 1
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
react-multi-process
=========================
multi process support to reactphp
Why use react-multi-process
-----------------------------
When we use `react/event-loop` to write async programs, we can not be sure
that every module is a no-blocking module(sync mysql client...).
So we use multi process to improve the performance of our sync program.
Import
-----------------------------
```shell
composer require jenner/react-multi-process
```
How to use it?
----------------------------------
So simple like:
```php
$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();
```