Skip to content
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

Integrate Server Sent event api (EventSource) or streaming HTTP api #135

Closed
theiosdevguy opened this issue Jul 20, 2018 · 1 comment
Closed
Labels

Comments

@theiosdevguy
Copy link

theiosdevguy commented Jul 20, 2018

I have a .NET based HTTP streaming api that I need to integrate on my larval based PHP server application. I have been using Guzzle for it but it is blocking my entire server because of the infinite while loop I had to place. I was exploring this library but I am encountering issues with it. The streaming api is built in a way that it requires a GET HTTP call which redirects to the streaming URL.

Example - GET http://192.168.1.25:4590 (with Auth headers)
Response - Redirects to http://192.168.1.25:4591 (Streaming API)

The problem I am facing is that when I do a GET to http://192.168.1.25:4590, I see no chunk of data in

$response->on('data', function ($chunk) {
        echo $chunk;
});

In fact, the logs suggest that

$response->on('end', function() { echo 'DONE'; });

is called right away.

Please suggest a mechanism to integrate such a streaming api. Or may be the right question here should be how to handle HTTP redirects?

@clue clue added the question label Jan 27, 2019
@clue
Copy link
Member

clue commented Jan 27, 2019

The streaming api is built in a way that it requires a GET HTTP call which redirects to the streaming URL.

Example - GET http://192.168.1.25:4590 (with Auth headers)
Response - Redirects to http://192.168.1.25:4591 (Streaming API)

@theiosdevguy Thanks for your patience and welcome to ReactPHP 🎉

The way this API seems to works means you may have to manually follow the redirect by sending a new request to the address given in the Location header. There are plans to support this automatically in the future via #20.

Once you send a request to this ServerSentEvents API, you should see individual chunks coming in via the data events. Parsing this shouldn't be too hard, given that SSE uses a very simple text-based protocol. This implementation is likely out of scope for this project, but we're happy to hear back if you happen to have an implementation for this! :shipit:

I hope this helps 👍

@clue clue closed this as completed Jan 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants