reactphp / reactphp

Event-driven, non-blocking I/O with PHP.

Home Page:https://reactphp.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

PHP Fatal error: Uncaught Error: Class "React\Http\HttpServer" not found

programarivm opened this issue · comments

Hi there,

It seems as if the current version of ReactPHP can't be used along with Ratchet 0.4. I just added the cli/tcp.php script to the PHP Chess Server codebase as per chesslablab/chess-server#153

<?php

namespace ChessServer\Cli;

use React\Http\HttpServer;
use React\Http\Message\Response;
use React\Socket\SocketServer;

require __DIR__  . '/../vendor/autoload.php';

$server = new HttpServer(function (Psr\Http\Message\ServerRequestInterface $request) {
    return Response::plaintext(
        "Hello World!\n"
    );
});

$socket = new SocketServer('127.0.0.1:8080');
$server->listen($socket);

echo "Server running at http://127.0.0.1:8080" . PHP_EOL;

However, React\Http\HttpServer is not included in cboden/ratchet v0.4.4.

php cli/tcp.php 
PHP Fatal error:  Uncaught Error: Class "React\Http\HttpServer" not found in /home/standard/projects/chess-server/cli/tcp.php:11
Stack trace:
#0 {main}
  thrown in /home/standard/projects/chess-server/cli/tcp.php on line 11

Thanks for the help,

We renamed React\Http\Server to React\Http\HttpServer when we merged in the client, but we left a shim React\Http\Server behind that you can still use with older version.

If using cboden/ratchet v0.4.4, the cli/tcp.php script still throws a PHP Fatal error with both React\Http\Server and React\Http\HttpServer. It looks like the PHP classes in the React\Http namespace are not included in Ratchet.

php cli/tcp.php 
PHP Fatal error:  Uncaught Error: Class "React\Http\Server" not found in /home/standard/projects/chess-server/cli/tcp.php:11
Stack trace:
#0 {main}
  thrown in /home/standard/projects/chess-server/cli/tcp.php on line 11
<?php

namespace ChessServer\Cli;

use React\Http\Server;
use React\Http\Message\Response;
use React\Socket\SocketServer;

require __DIR__  . '/../vendor/autoload.php';

$server = new Server(function (Psr\Http\Message\ServerRequestInterface $request) {
    return Response::plaintext(
        "Hello World!\n"
    );
});

$socket = new SocketServer('127.0.0.1:8080');
$server->listen($socket);

echo "Server running at http://127.0.0.1:8080" . PHP_EOL;

figure_01

composer require react/http should solve that