Skip to content

Instantly share code, notes, and snippets.

@WyriHaximus
Created April 20, 2022 19:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WyriHaximus/f4afc1fda73eca8ef5d27ed2b55bb2f5 to your computer and use it in GitHub Desktop.
Save WyriHaximus/f4afc1fda73eca8ef5d27ed2b55bb2f5 to your computer and use it in GitHub Desktop.
<?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