curl / Mailing Lists / curl-library / Single Mail


Re: How to Set Keep Alive Option in CURL

From: Praveen Pvs <>
Date: Wed, 4 Jan 2017 20:27:41 +0530

On Tue, Jan 3, 2017 at 12:33 AM, Ray Satiro via curl-library <> wrote:

> On 1/2/2017 9:16 AM, Praveen Pvs wrote:
> After setting the above options this what we have observed -
> We have sent in total three requests to the host(server).
> For the first request which was sent at 10:43:03 connection was
> established and handshake was done. For the second request which was sent
> at 10.:43:20 no handshake was done, directly data was being sent. The third
> request which was sent at 10:46:38 again performed handshake and sent the
> packet. According to keep alive feature it shouldn’t be performing again
> isn’t it ?
> Have attached the wireshark communication traces between client and server.
> Am I missing something here?
> We want to avoid SSL handshake with the server as much as possible?
> Another Question - Do we need to set both the options(
> Please do not send the same question to both lists, send it to the one
> most appropriate. For example in this case it's curl-library since you're
> speaking of libcurl and not the curl tool.
> Even if you use TCP keep-alive to get some earlier notice on potentially
> dead connections that doesn't put the server under any obligation to keep
> the connection, and it may close it if another transfer doesn't take place
> in a certain amount of time. For example, will close the
> connection after 3 minutes even if you use keep alive. Google IIRC closes
> after a similar amount of time.
> You don't have to set keepidle (default: 60) or keepintvl (default: 60).
> Those default values have been the same since the options were added, and
> I've just added that information to the documentation. As it says though
> "Not all operating systems support [these options]".
> You could monitor in Wireshark to confirm the keepalives are sent at the
> interval you requested. You should see a lot of black background/ red
> foreground type entries like
> [TCP Keep-Alive]
> [TCP Keep-Alive ACK]
> Check the timestamps to determine if the frequency is correct. If the
> server is closing the connection you should also see [FIN, ACK] or an RST
> Thank you for the response and sorry for posting to both the forums. If i
understand it correctly, if we use keep alive options also host could
still close the connection which is happening in my case. Adding to the
question on top of this: In this link
it says http headers for keep alive needs to be set accordingly like
connection-type, timeout value, max requests etc. Below is the header
generated by curl after enabling keep-alive. Why am I not seeing connection
type and keepalive timeout in the headers ? I am assuming curl will
generate them as it is required by HTTP header. Isnt that the case ?
Correct me if I am wrong.

*POST / HTTP/1.1*

*Host: <>*

*Accept: */**

*User-Agent:SCA v2.19.x*

*Content-Length: 952*

> -------------------------------------------------------------------
> List admin:
> Etiquette:

List admin:
Received on 2017-01-04