File: server.php

Recommend this page to a friend!
  Classes of Ahmad Mustapha  >  Simple React PHP HTTP Server  >  server.php  >  Download  
File: server.php
Role: Example script
Content type: text/plain
Description: Example script
Class: Simple React PHP HTTP Server
Pure PHP HTTP server using ReactPHP library
Author: By
Last change:
Date: 2 months ago
Size: 768 bytes
 

Contents

Class file image Download
<?php

use App\Server;
use
Psr\Log\NullLogger;
use
React\Cache\ArrayCache;
use
React\EventLoop\Factory;
use
React\Http\Server as ReactHttpServer;
use
React\Socket\Server as ReactSocketServer;
use
WyriHaximus\React\Http\Middleware\WebrootPreloadMiddleware;

require
'vendor/autoload.php';

define('ROOT_DIR', __DIR__ . '/');
define('CONTROLLER_NAMESPACE', 'App\\Controller\\');

$loop = Factory::create();

$socket = new ReactSocketServer(8080, $loop);
$server = new ReactHttpServer(
   
$loop,
    new
WebrootPreloadMiddleware('public', new NullLogger(), new ArrayCache()),
    new
Server(),
);

$server->on('error', function (Throwable $exception){
    echo(
$exception);
});

$server->listen($socket);

echo
"Server running at http://127.0.0.1:8080\n";

$loop->run();


For more information send a message to info at phpclasses dot org.