Created
November 22, 2014 09:04
-
-
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/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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