1 頁 (共 1 頁)

React

發表於 : 2013-10-16 12:00:53
yehlu
http://netkiller.github.io/php/react.html

http://reactphp.org/

https://github.com/reactphp/react

AN EXAMPLE: WEBSERVER

This simple web server written in React responds with "Hello World" for every request.

require 'vendor/autoload.php';

$app = function ($request, $response) {
$response->writeHead(200, array('Content-Type' => 'text/plain'));
$response->end("Hello World\n");
};

$loop = React\EventLoop\Factory::create();
$socket = new React\Socket\Server($loop);
$http = new React\Http\Server($socket, $loop);

$http->on('request', $app);
echo "Server running at http://127.0.0.1:1337\n";

$socket->listen(1337);
$loop->run();
To install, just run this command:

% composer init --require=react/http:0.3.* -n
% composer install
To run the server, put the code into a file example.php and execute it with the php program:

% php example.php
Server running at http://127.0.0.1:1337