CURLOPT_FRESH_CONNECT(3)

πŸ’… CURLOPT_FRESH_CONNECT(3) πŸ’…

okay bestie, so we're in the Library Functions Manual today and this one's about not reusing connections, which honestly is giving very "i need a fresh start, i'm reinventing myself" energy ✨ ngl it's kind of a slay. let's get into it 🫢


🌸 NAME 🌸

CURLOPT_FRESH_CONNECT β€” force a new connection to be used, no hand-me-downs, no sharing, periodt πŸ’…


πŸŽ€ SYNOPSIS πŸŽ€

#include <curl/curl.h>

CURLcode curl_easy_setopt(CURL *handle, CURLOPT_FRESH_CONNECT, long fresh);

literally just pass a long, babe 😌


✨ DESCRIPTION ✨

you pass a long here, okay? set it to 1 and the next transfer will use a new (fresh) connection by force instead of trying to reuse one that already exists. it's giving "i'm not going to the same party as my ex" honestly 😭

⚠️ real talk though: this option should be used with caution and only if you actually understand what it does β€” because it may impact performance negatively. not me warning you twice πŸ’€

there's a related little function called CURLOPT_FORBID_REUSE(3) which makes sure the connection is closed after use so that it cannot be reused. different vibe, same energy of refusing to share βœ‹

and if you set fresh to 0? then libcurl will attempt to reuse an existing connection. that's the default behavior, the chill one, the "yeah sure come through" of it all πŸ¦‹


🌈 DEFAULT 🌈

0

(so yes, by default it's chillin' and reusing 😌)


πŸ’– PROTOCOLS πŸ’–

this functionality affects all supported protocols β€” every single one, no exclusions, we love an inclusive icon πŸ‘‘


🧚 EXAMPLE 🧚

ok so here's the whole thing in action, and the comment is literally right there telling you what's happening πŸ‘‡

int main(void)
{
  CURL *curl = curl_easy_init();
  if(curl) {
    curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
    curl_easy_setopt(curl, CURLOPT_FRESH_CONNECT, 1L);
    /* this transfer must use a new connection, not reuse an existing */
    curl_easy_perform(curl);
    curl_easy_cleanup(curl);
  }
}

see the 1L? that's the fresh flag. icon behavior fr fr πŸ”₯


⭐ AVAILABILITY ⭐

added in curl 7.7 β€” so she's been around a minute, an elder icon honestly πŸŽ€


πŸ¦‹ RETURN VALUE πŸ¦‹

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

CURLE_OK (0) means everything was OK 😌 β€” any non-zero value means an error occurred, so go check libcurl-errors(3) and we'll figure it out together 🫢


πŸ‘‘ SEE ALSO πŸ‘‘


anyway that's the whole page bestie πŸ’œ this lil writeup came from libcurl, dated 2026-10-12, and it's the CURLOPT_FRESH_CONNECT(3) manual. hope it ate. mwah πŸŽ€βœ¨

πŸ“¦ where this page comes from