how to make curl re-use existing connection

0

1

curl --verbose google.com

If I execute this command, after curl does its job, it says "Connection #0 to host google.com left intact".

But it doesn't use same connection if I execute same command right after that. How can I make curl re-use same connection in second command?

Note: I don't want to use that command in below, because I have to do some bash scripting operations between two requests:

curl --verbose google.com --next google.com

dandidondi

Posted 2015-08-20T18:17:12.633

Reputation: 73

Answers

2

While searching around Google I found a couple of interesting answers and articles surrounding your question. Mainly the second answer given in https://stackoverflow.com/a/18047230/2901077 can help you understand not only how to use port reuse with libcurl but also when to use it.

Use the cURL_init function, implemented with PHP, to open a connection and the links includes reference's to the other two functions (curl_setopt & curl_exec) to be able to potentially reuse an existing handle (conncetion).

As a side note this answer, https://stackoverflow.com/a/982556/2901077 tells you how cURL handles new or existing requests. https://stackoverflow.com/a/15047105/2901077 is the answer though.

gh0st

Posted 2015-08-20T18:17:12.633

Reputation: 21

unfortunately I dont know C or PHP. Is it possible to do in command line? I have to use it in BASH – dandidondi – 2015-08-22T02:57:02.107

Well from what I understand if you reuse a handle you reuse the same connection. So take it for what it's worth. "http://serverfault.com/a/199446/284542"

– gh0st – 2015-08-22T09:57:06.533