CURLOPT_TCP_KEEPIDLE(3)

πŸ’€ CURLOPT_TCP_KEEPIDLE πŸ’€

okay so bestie, real talk: this is a libcurl thing β€” like, the manual name is CURLOPT_TCP_KEEPIDLE(3) and it lives in the curl library functions family, and it's literally the poster child for "how long do we just sit there before poking the server to check it's still alive."


🌸 NAME 🌸

CURLOPT_TCP_KEEPIDLE β€” the TCP keep-alive idle time wait. that's it. that's the vibe. 🫢


✨ SYNOPSIS ✨

#include <curl/curl.h>

CURLcode curl_easy_setopt(CURL *handle, CURLOPT_TCP_KEEPIDLE, long delay);

πŸ’… DESCRIPTION πŸ’…

so you pass a long, right? and that long is the delay, measured in seconds, that curl waits while the connection is just sitting there doing nothing before it starts sending keepalive probes. think of it as the "how long do I let them leave me on read before I double-text" timer. 😭

⚠️ not every operating system supports this option, so don't come for curl if your OS is being a hater.

and about the number itself: the max value this accepts is 2147483648. anything bigger than that gets capped to that amount. no cap, that's literally the cap. πŸ’€


πŸŽ€ DEFAULT πŸŽ€

60


πŸ¦‹ PROTOCOLS πŸ¦‹

this functionality affects tcp only. tcp girlies only, sorry. πŸ’œ


πŸ”₯ EXAMPLE πŸ”₯

int main(void)
{
  CURL *curl = curl_easy_init();
  if(curl) {
    curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");

    /* enable TCP keep-alive for this transfer */
    curl_easy_setopt(curl, CURLOPT_TCP_KEEPALIVE, 1L);

    /* set keep-alive idle time to 120 seconds */
    curl_easy_setopt(curl, CURLOPT_TCP_KEEPIDLE, 120L);

    /* interval time between keep-alive probes: 60 seconds */
    curl_easy_setopt(curl, CURLOPT_TCP_KEEPINTVL, 60L);

    /* maximum number of keep-alive probes: 3 */
    curl_easy_setopt(curl, CURLOPT_TCP_KEEPCNT, 3L);

    curl_easy_perform(curl);
  }
}

like, look at her go. setting the idle time to 120 seconds, intervals of 60, max 3 probes. main character networking energy fr fr. 🌈


⭐ AVAILABILITY ⭐

added in curl 7.25.0. she's been iconic since day one, we stan an OG. πŸ‘‘


🧚 RETURN VALUE 🧚

curl_easy_setopt(3) returns a CURLcode indicating success or error.

CURLE_OK (which is 0, bestie β€” zero is the good one here) means everything was OK. non-zero means an error occurred, and you should go see libcurl-errors(3) for the whole lore. 😭


🌸 SEE ALSO 🌸


πŸ’– okay that's the whole page, you ate that. go forth and keep those connections alive.

mwah πŸ’‹ β€” this page was brought to you by libcurl, dated 2026-10-12, and yes the title up top is CURLOPT_TCP_KEEPIDLE(3) in case you forgot already. byeeee πŸŽ€βœ¨

πŸ“¦ where this page comes from