Skip to content

Commit 4eaf63f

Browse files
author
Eugene Tupikov
committed
First implementation
1 parent 60567a1 commit 4eaf63f

19 files changed

+1728
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
vendor/*
2+
.idea/*

cluster.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
// a simple, single-process, horizontal scalable http server listening on 10 ports
4+
require __DIR__.'/vendor/autoload.php';
5+
$loop = React\EventLoop\Factory::create();
6+
for ($i=0;$i<10;++$i) {
7+
$s=stream_socket_server('tcp://127.0.0.1:'.(8000+$i));
8+
$loop->addReadStream($s, function ($s) use ($i) {
9+
$c=stream_socket_accept($s);
10+
$len=strlen($i)+4;
11+
fwrite($c,"HTTP/1.1 200 OK\r\nContent-Length: $len\r\n\r\nHi:$i\n");
12+
echo "Served on port 800$i\n";
13+
});
14+
}
15+
echo "Access your brand new HTTP server on 127.0.0.1:800x. Replace x with any number from 0-9\n";
16+
$loop->run();

composer.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"minimum-stability": "stable",
3+
"require": {
4+
"react/react": "*",
5+
"phroute/phroute": "*",
6+
"guzzlehttp/guzzle": "~6.0"
7+
8+
},
9+
"autoload": {
10+
"psr-4": {
11+
"unclead\\phpcluster\\": "src/"
12+
}
13+
}
14+
}

0 commit comments

Comments
 (0)