Basically, it is very similar to Node.js, but in PHP. It is called React PHP. It is an asynchronous non-blocking I/O evented platform. Sound familiar? Even the code will look quite familiar to node devs:
Code: Select all
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();
Of course, React's community would have to be a grain of sand compared to node's, and that does bring about certain challenges. But for those interested in playing on the bleeding edge of PHP or for those who come from a PHP background and just can't get used to node, this could be an option. What it needs now is its own version of Express
