-
-
Notifications
You must be signed in to change notification settings - Fork 126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ReactHttp server integretion problem #188
Comments
The dispatcher is only actually designed to dispatch one request, as far as I can tell, this setup would be dispatching multiple times |
yes. you are right. if i create router onRequest function then it works perfectly. I want to read all the routes from the files at once to reduce I/O. pls advise how can i implement this things ? |
I don’t have much experience with reactphp unfortunately but if you need to dispatch more than once that’s just not going to be possible.
…Sent from my iPhone
On 11 Sep 2018, at 14:42, Mohammad Emran ***@***.***> wrote:
yes. you are right. if i create router onRequest function then it works perfectly. I want to read all the routes from the files at once to reduce I/O. pls advise how can i implement this things ?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or mute the thread.
|
In this way, core Fast Route library is working fine without giving any error. it dispatched when new request come and return response. can u check pls following function.
|
You are correct. FastRoute is at the core of league/route but it adds a lot more functionality which makes it harder to be able to dispatch more than once, I’m not saying it will never be possible but currently it is not
…Sent from my iPhone
On 11 Sep 2018, at 15:16, Mohammad Emran ***@***.***> wrote:
In this way, core Fast Route library is working fine without giving any error. it dispatched when new request come and return response.
can u check pls following function.
public function dispatch(ServerRequestInterface $request) : ResponseInterface { if (is_null($this->getStrategy())) { $this->setStrategy(new ApplicationStrategy); } $this->prepRoutes($request); return (new Dispatcher($this->getData())) ->middlewares($this->getMiddlewareStack()) ->setStrategy($this->getStrategy()) ->dispatchRequest($request) ; }
On the above function, $this->prepRoutes($request); If i am not wrong, this could be call on class [with some modification] before dispatch function called as it is not associated with request.I think it is route building function. pls correct me if am wrong.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or mute the thread.
|
ok..thanks. i have updated Router.php scripts and it works fine. just sharing with u if you find any beneficial then you can apply as patch . `public function buildRoute(): self
Here is the application final code:
other way it can be done like when map and group function will be called, it will directly addRoute to the routes list. Thanks for your quick response and great contribution to the php community. |
i m trying to use league/route with reactphp http server. it works fine at first request.After that it gives error like this.
My complete code is like this:
`<?php
include 'vendor/autoload.php';
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\ResponseInterface;
use React\EventLoop\Factory;
use React\Http\Response;
use React\Http\StreamingServer;
use React\Http\Server;
$router = new League\Route\Router;
//map a route
$router->get('/', function (ServerRequestInterface $request) : ResponseInterface
{
$response = new \Zend\Diactoros\Response;
$response->getBody()->write("
Hello, World!
");return $response;
});
$onRequest = function (ServerRequestInterface $request) use ($router){
};
$loop = Factory::create();
$server = new StreamingServer($onRequest);
$server->on('error', function (Exception $e) {
echo 'Error: ' . $e->getMessage() . PHP_EOL;
if ($e->getPrevious() !== null) {
$previousException = $e->getPrevious();
echo $previousException->getMessage() . PHP_EOL;
}
});
$socket = new \React\Socket\Server(isset($argv[1]) ? $argv[1] : '0.0.0.0:1337', $loop);
$server->listen($socket);
echo 'Listening on ' . str_replace('tcp:', 'http:', $socket->getAddress()) . PHP_EOL;
$loop->run();
`
The text was updated successfully, but these errors were encountered: