Skip to content

Instantly share code, notes, and snippets.

@tabuna
Last active June 13, 2018 10:26
Show Gist options
  • Save tabuna/d82c1bba3a384b89e69a81e3f3f06a0a to your computer and use it in GitHub Desktop.
Save tabuna/d82c1bba3a384b89e69a81e3f3f06a0a to your computer and use it in GitHub Desktop.
Lumen & React PHP
<?php
//"react/event-loop": "^0.4.3",
//"react/http": "^0.7.2",
//"symfony/psr-http-message-bridge": "^1.0"
/*
|--------------------------------------------------------------------------
| Create The Application
|--------------------------------------------------------------------------
|
| First we need to get an application instance. This creates an instance
| of the application / container and bootstraps the application so it
| is ready to receive HTTP / Console requests from the environment.
|
*/
$app = require __DIR__.'/../bootstrap/app.php';
/*
|--------------------------------------------------------------------------
| Run The Application
|--------------------------------------------------------------------------
|
| Once we have the application, we can handle the incoming request
| through the kernel, and send the associated response back to
| the client's browser allowing them to enjoy the creative
| and wonderful application we have prepared for them.
|
*/
//$app->run();
use Symfony\Bridge\PsrHttpMessage\Factory\HttpFoundationFactory;
$loop = React\EventLoop\Factory::create();
$httpFoundationFactory = new HttpFoundationFactory();
$server = new React\Http\Server(function (Psr\Http\Message\ServerRequestInterface $reactRequest) use ($app,$httpFoundationFactory) {
$symfonyRequest = $httpFoundationFactory->createRequest($reactRequest);
$response = $app->handle($symfonyRequest);
return new React\Http\Response(
$response->getStatusCode(),
$response->headers->all(),
$response->getContent()
);
});
$socket = new React\Socket\Server(8080, $loop);
$server->listen($socket);
$loop->run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment