Skip to content

Instantly share code, notes, and snippets.

@coreymcmahon
Created November 22, 2014 09:04
Show Gist options
  • Save coreymcmahon/093901e8252d6e63f8f1 to your computer and use it in GitHub Desktop.
Save coreymcmahon/093901e8252d6e63f8f1 to your computer and use it in GitHub Desktop.
The 12 Factor App: Port binding example with ReactPHP - http://slashnode.com/the-12-factor-php-app-part-2/
<?php
include __DIR__.'/vendor/autoload.php';
$app = function ($request, $response) {
$body = "" . time();
$response->writeHead(200, ['Content-Type' => 'text/plain']);
$response->end($body);
};
$loop = React\EventLoop\Factory::create();
$socket = new React\Socket\Server($loop);
$http = new React\Http\Server($socket, $loop);
$http->on('request', $app);
// set the port, start listening on the port
$socket->listen(8000);
$loop->run();
/* server running at localhost:8000 ... */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment