PHP node alternative?
Posted: Sun Mar 30, 2014 8:07 pm
This is pretty interesting. I don't know if it is a good idea to use it in production, but it is interesting nevertheless.
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:
You could almost just take out the dollar signs and have the classic node web server example. It even have its own version of Socket.io called Ratchet. The thing is, I think I actually posted Ratchet here quite some time ago. It actually existed before React PHP did, and simply used a blocking I/O scheme in PHP CLI. They had to actually say on their website to not use it in production since it would fall apart after 10 or 12 users connected (due to blocking the thread). But Ratchet has new life with the creation of React PHP, now that it has a platform that can allow it to scale much better.
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
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