PHP Classes

File: test-react.php

Recommend this page to a friend!
  Classes of Ahmad Mustapha   PHP Application Server   test-react.php   Download  
File: test-react.php
Role: Example script
Content type: text/plain
Description: Example script
Class: PHP Application Server
Run application with different types of Web server
Author: By
Last change:
Date: 2 years ago
Size: 548 bytes
 

Contents

Class file image Download
<?php

use PHPServer\React\Server;
use
Psr\Http\Message\RequestInterface;
use
React\Http\Message\Response;

require
'vendor/autoload.php';

$handler = function (RequestInterface $request) {
   
$html = 'Welcome,<br/>';
   
$html .= "Method: {$request->getMethod()}<br/>";
   
$html .= "Route: {$request->getUri()->getPath()}";
    return new
Response(200, ['Content-Type' => 'text/html'], $html);
};

Server::create('127.0.0.1', 9904)
    ->
onRequest($handler)
    ->
start()
    ->
onStdout(function (string $data) {
       
var_dump($data);
    });