Skip to content

pre-connect to remote hosts #18539

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

Closed
staabm opened this issue May 12, 2025 · 9 comments
Closed

pre-connect to remote hosts #18539

staabm opened this issue May 12, 2025 · 9 comments

Comments

@staabm
Copy link
Contributor

staabm commented May 12, 2025

Description

browser have a html tag to pre-connect to hosts, also bun (a competitor to nodejs) added support for pre-connecting to hosts, like databases, http-hosts etc.

the benchmarks shared by the bun team (see above links) look like there is a considerable amount of time to be saved, in case the connection is used often enough/the hosts have enough distance in between.

I wonder whether PHP could also provide such kind of startup-time pre-connect things so we don't need to re-establish connections at every request.
DNS resolution or TLS connection handshakes could already be completed before the PHP script beeing run even knows it will need it later

@ddevsr
Copy link

ddevsr commented May 13, 2025

This is related to cURL? CURLOPT_FORBID_REUSE and CURLOPT_FRESH_CONNECT with false? or CURLOPT_RESOLVE for skip DNS resolution? Nice idea to have pre-connect at level startup time (FPM?)

+1 for me. Can you start writting RFC?

@staabm
Copy link
Contributor Author

staabm commented May 13, 2025

I think its related to anything which can open a stream. At best it would work for all/most SAPIs.

Maybe thats something which be be triggered during class-preloading. There might be a better alternative thought.

@TimWolla
Copy link
Member

@bukka
Copy link
Member

bukka commented May 31, 2025

Are you basically talking about worker mode like in FrankenPHP? That's doable on the FPM side as well - it just requires a bit of works and few other things to work right in FPM and possibly in apache2handler.

@staabm
Copy link
Contributor Author

staabm commented Jun 2, 2025

No I don't mean worker mode.

I was asking for, whether it is possible to warmup connections to certain hosts (before they are actually required at runtime), so connection establish overhead (TLS handshake, TCP handshake,..) will not hit at runtime, but before a user sits in front and waits for the results synchronously

@bukka
Copy link
Member

bukka commented Jun 5, 2025

Well you need to somehow create the connection so it really depends what sort of API you have in mind. Worker is one option that can keep long term connection in the script before the script is actually hit. Then you have persistent ones but those still have hit on the first connection and they often suffer from not proper closing and accumulating connections on server. Maybe what you are looking for is some sort of better / managed persistence like connection pools but they usefulness depends on SAPI.

There was also bootstrapping proposed for FPM but it's not working great for keepalive fcgi connections as there is still some wait time.

So I guess you need to be a bit more specific about the proposed API.

@bukka
Copy link
Member

bukka commented Jun 5, 2025

Here is a bit more info about early bootstrapping issue: #11723 (comment) .

@bukka
Copy link
Member

bukka commented Jun 5, 2025

Currently I don't even know how to label this as you didn't actually say what SAPI you would like to see this or how this should be driven. There are just too many unknowns and not sure if it this is even something for GH issues - we should have here only specific feature requests that have concrete vision and details. Not just something generic for discussion.

@staabm
Copy link
Contributor Author

staabm commented Jun 5, 2025

I see. thanks for all the feedback.

will close for now until I have a more clear vision on how this thing can/should work

@staabm staabm closed this as completed Jun 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants