Skip to content

Allow to set CURLOPT_FORBID_REUSE when constructing http curl client #40482

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
simPod opened this issue Mar 16, 2021 · 6 comments
Closed

Allow to set CURLOPT_FORBID_REUSE when constructing http curl client #40482

simPod opened this issue Mar 16, 2021 · 6 comments

Comments

@simPod
Copy link
Contributor

simPod commented Mar 16, 2021

Description

Currently, CurlHttpClient has a set of allowed options that can be passed on construction and then they're converted to curl opts internally.

However, the CURLOPT_FORBID_REUSE is not mapped to any option and therefore it's impossible to use when relying on PSR interfaces.
Symfony request() method allows to pass options through 3rd arg via extra.curl but I don't want to use that option nor interface as it exposes implementation details.

I'm making http requests to devices that has unreliably implemented HTTP. Therefore it is required to force TCP connection to close in order to enforce some stability. And that's done using CURLOPT_FORBID_REUSE.

Example

Would it make sense to add forbid_reuse: true|false option that can be passed into new CurlHttpClient(['forbid_reuse': false])? I don't see any other way to do so.

@nicolas-grekas
Copy link
Member

As allowed by #38026?

@nicolas-grekas
Copy link
Member

I don't want to use that option nor interface as it exposes implementation details.

Oh, I read to fast your description. Still, this extra entry is the way IMHO.

@nicolas-grekas
Copy link
Member

nicolas-grekas commented Mar 16, 2021

You could use an HttpClientFactory service to achieve what you describe - this would effectively prevent connections from being reused, by creating a new client instance when needed.

@simPod
Copy link
Contributor Author

simPod commented Mar 16, 2021

I checked the construction source code before but did not find explicit use of extra.curl there so it confused me. You are right, I can use that, thank you. I guess this is solved then.

I did not find any HttpClientFactory class though. However, I have an experience that even though I created a new Client instance before every request, it was still reusing connections (in long running php processes).

@nicolas-grekas
Copy link
Member

I did not find any HttpClientFactory class though

There is none, that would be yours to create :)

even though I created a new Client instance before every request, it was still reusing connections

That'd be strange, I don't know how this can happen, knowing the code.

Closing as solved then.

@simPod
Copy link
Contributor Author

simPod commented Mar 16, 2021

Ah, ok, I get what you mean. I have a factory service.

Anyway, it's different problem, different code.

Thanks ;)

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

No branches or pull requests

2 participants