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

Accessing the Connection object #451

Closed
bpolaszek opened this issue Apr 14, 2022 · 2 comments
Closed

Accessing the Connection object #451

bpolaszek opened this issue Apr 14, 2022 · 2 comments
Labels

Comments

@bpolaszek
Copy link

Hello there! 👋

I'm the maintainer of Freddie, a Mercure hub implementation leveraging Framework X and react/http - its job is mostly to broadcast Server-Sent Events.

Whenever a new request comes up, the request handler subscribes to a Redis channel and drops messages into the response body as soon as they come up. Problem is, whenever the connection closes, I have no means to get notified of that event, as the Connection object is kept internal by react/http. On my side, this leads to redis subscribers kept subscribed, and performance degradations over time.

Unsure if it would be crappy or legit, but an easy way to tackle this would be to inject the connection object inside the request, so that we could access it through something like $serverRequest->getAttribute('connection'). That's what Symfony already does with its own Request system (prefixing attributes by an underscore to mark them internal). WDYT?

@bpolaszek
Copy link
Author

Nevermind - ThroughStream objects also emit close events, meaning I don't require to rely on the Connection object.

Other use case I had was to access Connection::getRemoteAddress() for some other purpose, but the remote address is exposed into $request->getServerParams(), so that makes my proposal unrelevant, as I currently don't see other use cases.

Sorry for polluting!

@clue
Copy link
Member

clue commented Apr 14, 2022

@bpolaszek Thanks for reporting and glad you've got this sorted out already!

This is useful input, I've just filed #452 to add some documentation to make sure the close event is easier to find in the future 👍

Regarding exposing the connection instance to access connection properties such as the socket addresses or TLS details, there's a similar discussion in #324, let's continue this discussion there 👍

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