-
-
Save WyriHaximus/f4afc1fda73eca8ef5d27ed2b55bb2f5 to your computer and use it in GitHub Desktop.
This file contains 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 | |
// $ composer require react/http react/socket # install example using Composer | |
// $ php example.php # run example on command line, requires no additional web server | |
require __DIR__ . '/vendor/autoload.php'; | |
$http = new React\Http\HttpServer(function (Psr\Http\Message\ServerRequestInterface $request) { | |
return React\Http\Message\Response::plaintext( | |
"Hello World!\n" | |
); | |
}); | |
$socket = new React\Socket\SocketServer('127.0.0.1:8080'); | |
$http->listen($socket); | |
echo "Server running at http://127.0.0.1:8080" . PHP_EOL; | |
Loop::addSignal(SIGINT, $func = function ($signal) use (&$func, $http) { | |
echo 'Signal: ', (string)$signal, PHP_EOL; | |
Loop::removeSignal(SIGINT, $func); | |
$http->close(); | |
}); | |
Loop::addSignal(SIGTERM, $func = function ($signal) use (&$func, $http) { | |
echo 'Signal: ', (string)$signal, PHP_EOL; | |
Loop::removeSignal(SIGTERM, $func); | |
$http->close(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment