-
Notifications
You must be signed in to change notification settings - Fork 22
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
Allow to configure connect timeout separately #22
Conversation
Friendly ping @daniel-jones-deepl, @JanEbbing. |
Hi @VincentLanglet , sorry, Daniel is out at the moment. I see 2 broad ways to achieve this.
My asks:
|
Yes, I understand. I tried to introduce as few changes as possible:
For context, I currently use the following code (with this PR)
For the "better" solution, I would say it depends on the amount of time/work/changes you want to take @JanEbbing. Allowing to pass the HttpClient to the Translator seems to be the more flexible solution (with a default http implementation) ; but to me it's also the solution which might require the more change in the Deepl codebase.
Even if the HttpClient is now an entry-point, it still could be helpful to allow people to pass some curl options to the HttpClient, in order to not having to rewrite a whole HttpClient if they want to change the timeout. So to me the solutions 1 and 2 are not incompatible. You could have a
And people could write either
Still, this could require a way to override Something like
Does it answer all your questions ? Do you plan to implements such change alone/with your team or should/can I help ? |
Hi @JanEbbing, is there anything to do on my side ? I would have expected a short answer to know
|
Hi Vincent, sorry for the lack of transparency here. We'll ultimately move all development to GitHub, then it's easier to see what we're working on. |
Thanks for your quick answer, I'm impatient to try this feature (and stop using a temporary fork). |
Hi @VincentLanglet , I added support for custom clients in a new branch. We plan to merge this in the next version, please let me know what you think. |
Hi, this seems an ok implementation. The only things I see which might be improve (but I'm not certain how), would be to remove the hard dependency to I saw @nicolas-grekas promoting /~https://github.com/php-http/discovery which does an auto-discovery of the right psr implementation. The goal would be to use
but I'm not sure how easy it is to use this ; and this can still be done in another PR if needed. |
Thanks, that seems like a great way to avoid a dependency on a PSR-7 implementation! |
Another idea: We could also require a PSR-7/PSR-17 HTTP factory to be passed in with the PSR-18 HTTP client. This would mean no direct dependencies(*), but it would make the library interface a little harder to use. *: edited-to-add: actually there would need to be a psr/http-factory dependency. |
I would definitely recommend relying on php-http/discovery and using its As far as timeout is concerned, this could be considered out of scope from an SDK pov (aka let users that care do the timeout configuration as part of their wiring) or we could also discuss a way to make You might want to check helpscout/helpscout-api-php#311 for inspiration. |
@nicolas-grekas Thanks for the code example. We use POST requests with Is there any way around using that? |
Instead of this discovery class, you should use /~https://github.com/php-http/multipart-stream-builder $client = new Psr18Client();
$builder = new MultipartStreamBuilder($client); |
Thanks! I implemented that change and removed the guzzle dependency on the branch. |
Hi @JanEbbing, |
Hi @JanEbbing, what are the next step for your branch ? Is it ready to be reviewed/merged/released ? :) |
Yes, this (with some other fixes) will be released today. |
Thanks |
Hi @daniel-jones-deepl,
Currently, Deepl only allow one option:
TranslatorOptions::TIMEOUT
.This one is used for both
But we might accept a CURLOPT_TIMEOUT_MS of 30s while we want a low CURLOPT_CONNECTTIMEOUT.
In general it doesn't make a lot of sens to have more than a few seconds for the connect timeout.
So it should be better to split both option
TranslatorOptions::CONNECT_TIMEOUT
TranslatorOptions::EXEC_TIMEOUT
To keep the old behavior, I kept the
TranslatorOptions::TIMEOUT
option which is used as a default value for bothCONNECT_TIMEOUT
andEXEC_TIMEOUT
Also, the doc was saying
So I changed it to
connect_timeout
. (Even iftimeout
will still work for the BC compatibility).I'm open to any feedback :)