1. Go to this page and download the library: Download jalle19/react-http-static library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
jalle19 / react-http-static example snippets
alle19\ReactHttpStatic\Authentication\Handler\Basic as BasicAuthenticationHandler;
use React\Http\Server as HttpServer;
use React\Socket\Server as Socket;
// Create an event loop. You'll probably want to use your own application's loop instead of creating a new one.
$eventLoop = \React\EventLoop\Factory::create();
// Create the socket to use
$socket = new Socket($eventLoop);
$socket->listen(8080);
// Create the server itself
$httpServer = new HttpServer($socket);
$staticWebServer = new Jalle19\ReactHttpStatic\StaticWebServer($httpServer, '/var/www');
// Apply our authentication handler
$handlerCallback = function ($username, $password) {
return $username === 'admin' && $password === 'admin';
};
$staticWebServer->setAuthenticationHandler(new BasicAuthenticationHandler('our fancy realm', $handlerCallback));
// Start the loop
$eventLoop->run();