Created
May 10, 2012 14:01
-
-
Save cboden/2653190 to your computer and use it in GitHub Desktop.
Libevent React
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require __DIR__.'/vendor/autoload.php'; | |
error_reporting(E_ALL | E_STRICT); | |
ini_set('display_errors', 1); | |
//$loop = new React\EventLoop\StreamSelectLoop(); | |
$loop = new React\EventLoop\LibEventLoop(); | |
$socket = new React\Socket\Server($loop); | |
$i = 1; | |
$socket->on('connect', function ($conn) use (&$i, $loop) { | |
echo "new connection $i\n"; | |
$i++; | |
$conn->on('data', function ($data) use ($conn, &$i) { | |
$response = "Hello World!\n"; | |
$length = strlen($response); | |
$conn->write("HTTP 1.1 200 OK\r\n"); | |
$conn->write("Content-Type: text/plain\r\n"); | |
$conn->write("Content-Length: $length\r\n"); | |
$conn->write("\r\n"); | |
$conn->write($response); | |
$conn->end(); | |
}); | |
}); | |
$socket->listen(8000); | |
$loop->run(); | |
/* | |
$ telnet localhost 8000 | |
> (hit return) | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment