Skip to content
This repository has been archived by the owner on Oct 3, 2023. It is now read-only.

How to implement in a ReactPHP app? #214

Open
acasademont opened this issue Oct 21, 2018 · 5 comments
Open

How to implement in a ReactPHP app? #214

acasademont opened this issue Oct 21, 2018 · 5 comments

Comments

@acasademont
Copy link

Hi! Seems like the library is heavily geared towards the classic PHP single-request mode. How should I instrument my code for a ReactPHP use case? A single PHP process handles multiple requests.

Thanks!

@jcchavezs
Copy link
Contributor

jcchavezs commented Oct 22, 2018 via email

@acasademont
Copy link
Author

Sure, this is taken from ReactPHP's website, for example

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

$server = new React\Http\Server(function (Psr\Http\Message\ServerRequestInterface $request) {
    //Lots of calls and work here
    return new React\Http\Response(
        200,
        array('Content-Type' => 'text/plain'),
        "Hello World!\n"
    );
});

$socket = new React\Socket\Server(8080, $loop);
$server->listen($socket);

echo "Server running at http://127.0.0.1:8080\n";

$loop->run();

This is script runs indefinitely, serving an undefined number of requests.

@jcchavezs
Copy link
Contributor

jcchavezs commented Oct 31, 2018 via email

@acasademont
Copy link
Author

@jcchavezs yes exactly. We're right now using PHP-PM which limits concurrency for the ReactPHP loops but in theory they could be running in parallel. ReactPHP has the concept of Middlwares that let's you manipulate the request object and pass some kind of context.

https://reactphp.org/http/#middleware

And in theory that ReactPHP process is never killed in the sense of a traditional php request-response, so having stuff in destructors is not recommended, it might take a long time until they are executed.

@basvanbeek
Copy link
Member

Unfortunately the current implementation of OpenCensus Tracing expects a standard isolated PHP Request lifecycle and is thus incompatible with event driven PHP solutions like ReactPHP.

Given enough demand this might change in the future. OpenCensus Stats should actually work quite nicely as it allows for both implicit as well as explicit scope handling.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants