whatsmyname
whatsmyname

Reputation: 71

Uncaught Error: Class 'React\React\EventLoop\Factory' not found

When I run php server.php I get the following error:

Fatal error: Uncaught Error: Class 'React\React\EventLoop\Factory' not found in C:\xampp\htdocs\socket\server.php:7

I used composer to grab composer require react/socket:^1.3 Require the autoload.php

use React\Http\Server;

require 'vendor/autoload.php';

$loop = React\EventLoop\Factory::create();
$connector = new React\Socket\Connector($loop);

$connector->connect('127.0.0.1:8080')->then(function (React\Socket\ConnectionInterface $connection) use ($loop) {
    $connection->pipe(new React\Stream\WritableResourceStream(STDOUT, $loop));
    $connection->write("Hello World!\n");
});

$loop->run();

Upvotes: 1

Views: 3074

Answers (1)

Jerin Monish
Jerin Monish

Reputation: 115

Hi i too has a similar issue then at first, try to install event loop package by using these commands composer require react/event-loop or composer require react/event-loop:^1.1 and then try to use composer update command.

1.your composer should like this finally after installing all the packages.

{
    "require": {
        "react/http": "^0.8.5",
        "react/mysql": "^0.5.4",
        "nikic/fast-route": "^1.3",
        "react/event-loop": "^1.1"
    },
    "autoload": {
        "psr-4": {
            "App\\": "src/"
        }
    }
}

  1. You index.php must look like this

<?php
require('vendor/autoload.php');

use React\Http\Response;
use React\Http\Server;
use React\MySQL\Factory;

$loop = \React\EventLoop\Factory::create();

$hello = function () {
    return new Response(200, ['Content-type' => 'text/plain'], 'Hello');
};

$server = new Server($hello);
$socket = new \React\Socket\Server('127.0.0.1:8000', $loop);
$server->listen($socket);

echo 'Listening on ' . str_replace('tcp:', 'http:', $socket->getAddress()) . PHP_EOL;
$loop->run();

And then try to use php index.php it must run. For me it worked. Hope it might help you !

Upvotes: 1

Related Questions