0

I am newbie. Trying to install react php to make a asynchronous server. I installed it using composer require react/react. And then included the autoload.php in the code. But it is not able to autoload the required files. I have written this code

`<?php

require_once '../vendor/autoload.php';

$i = 0;
$app = function ($request, $response) use (&$i) {
    $i++;
    $text = "This is request number $i.n";
    $headers = array('Content-Type' => 'text/plain');

    $response->writeHead(200, $headers);
    $response->end($text);
};

$loop = ReactEventLoopFactory::create();
$socket = new ReactSocketServer($loop);
$http = new ReactHttpServer($socket);

$http->on('request', $app);

$socket->listen(1337);
$loop->run();

?>

` This is my composer json

{
    "require": {
        "react/react": "*"
    }
}

This is my vendor folder structure

-Vendor
   -react
   -evenement
   -psr
   -composer
Tushar Kundra
  • 29
  • 2
  • 6
  • PS: I think that i need to add autoload in composer.json but i dont know how to add it. Any help would be appreciated – Tushar Kundra Jun 10 '16 at 04:57
  • I think you first need to learn how both namespacing and composer work. Also if you paste what error you where getting it makes it easier to know what might be wrong. Having a quick look at the code probably is because you didn't include the full namespace of the React things you are using. – Jhuliano Moreno Aug 05 '16 at 12:54

1 Answers1

0

Solved it. I copied the composer.json from the reactphp https://github.com/reactphp/react and then run the following command

1) composer install 2) composer dumpautoload -o 3) include composer autoload.php in my code

Tushar Kundra
  • 29
  • 2
  • 6