4

The following is from the libcurl homepage:

curl and libcurl have excellent support for persistent connections when transferring several files from the same server. Curl will attempt to reuse connections for all URLs specified on the same command line/config file, and libcurl will reuse connections for all transfers that are made using the same libcurl handle.

Just to be sure, if I create a CURL handle (curl_easy_init()) and set it's headers, make a HTTP-request, then change the headers and make another request, libcurl will still attempt to use a persistent connection even though the headers have changed?

The libcurl homepage also says

If you use the easy interface, and you call curl_easy_cleanup, all the possibly open connections held by libcurl will be closed and forgotten.

So as long as I dont call curl_easy_cleanup, CURL will attempt to re-use the same connection even though the requests are made with different headers?

Thank you.

1 Answer 1

11

Yes, that's entirely correct. Keep re-using the same easy handle and libcurl will try to re-use connections as much as possible.

10
  • @daniel-stenberg I have a similar doubt. I understand that the handle will reuse the connections until closed but does that mean I never cleanup that handle? For ex: function B handle calls to the http server and function A use to call B frequently, so if I cleanup the handle in B then every call from A will create new connections to http server. Am I right in understanding? Please guide. Commented Jul 21, 2015 at 21:52
  • 2
    Sorry, but adding a second question in a comment to an answer seems like very bad form. Ask a new question, read the docs or ask on the libcurl mailing list. Commented Jul 21, 2015 at 22:04
  • 1
    @daniel-stenberg I am sorry but I thought a similar question will be marked as duplicate and closed so just asked here. No problem, I have asked it as question. Actually I have a bigger doubt but this was small part of it. Commented Jul 22, 2015 at 4:46
  • 9
    @FlorianWinter sorry but I wrote the code. I know it works like this, even without a link to corroborate it. Commented Jul 20 at 16:17
  • 2
    @FlorianWinter That’s the founder and maintainer of cURL. They’re inherently a primary and reputable source on its functionality.
    – ceejayoz
    Commented Jul 20 at 16:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.