CURLOPT_MAXCONNECTS(3)
π CURLOPT_MAXCONNECTS(3) β like, the maximum connection cache size, bestie
okay so this is from the Library Functions Manual, and the whole page is literally about CURLOPT_MAXCONNECTS(3). yes that's the function-slash-option-slash-icon we're stanning today. let's get into it π
β¨ NAME β¨
CURLOPT_MAXCONNECTS β maximum connection cache size. that's it. that's the tweet. π¦
πΈ SYNOPSIS πΈ
#include <curl/curl.h>
CURLcode curl_easy_setopt(CURL *handle, CURLOPT_MAXCONNECTS, long amount);
so you're passing a long in as amount, and calling it on your handle via curl_easy_setopt. iconic signature, no notes. π«Ά
π DESCRIPTION π
okay so you pass a long, and that amount you set is the maximum number of connections that libcurl may keep alive in its connection cache after use. like, after it's done with them, it holds onto them. that's the cache. that's what this caps. π§
the default is 5 β and ngl, there is not much point in changing this value unless you are perfectly aware of how this works. like, fr fr, don't just start yanking this number around for the vibe. know what you're doing first. this concerns connections using any of the protocols that support persistent connections.
when it reaches the maximum limit, curl closes the oldest connection present in the cache, so that the number of connections doesn't keep increasing. oldest one gets evicted first. she's done her time. bye bestie π
and here's the cautionary part, listen up: if you already have performed transfers with this curl handle, setting a smaller CURLOPT_MAXCONNECTS(3) than before may cause open connections to get closed unnecessarily. so like... don't shrink it mid-relationship, it gets messy. π
also important, and this is the plot twist: if you add this easy handle to a multi handle, this setting is not acknowledged. like she does not get the memo. you must instead use curl_multi_setopt(3) and the CURLMOPT_MAXCONNECTS(3) option. periodt.
π DEFAULT π
5
five. that's the number. main character number. π
π PROTOCOLS π
this functionality affects all supported protocols. all of them. every single one. she's versatile like that. β
π₯ EXAMPLE π₯
int main(void)
{
CURL *curl = curl_easy_init();
if(curl) {
CURLcode result;
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
/* limit the connection cache for this handle to no more than 3 */
curl_easy_setopt(curl, CURLOPT_MAXCONNECTS, 3L);
result = curl_easy_perform(curl);
}
}
look at that comment β /* limit the connection cache for this handle to no more than 3 */ β she said three, max. we respect it. π
π AVAILABILITY π
Added in curl 7.7. vintage. an elder icon. π
β RETURN VALUE β
curl_easy_setopt(3) returns a CURLcode indicating success or error.
CURLE_OK (0) means everything was OK. non-zero means an error occurred, and you should go see libcurl-errors(3) for the tea. π
π¦ SEE ALSO π¦
CURLMOPT_MAXCONNECTS(3)CURLMOPT_MAX_HOST_CONNECTIONS(3)CURLMOPT_MAX_TOTAL_CONNECTIONS(3)CURLOPT_MAXREDIRS(3)
ok that's the whole page, go forth and cache responsibly, don't shrink your cache on a live handle, and remember: multi handle = different option entirely. iykyk π
libcurl πΈ 2026-10-12 πΈ CURLOPT_MAXCONNECTS(3) β mwah, that's a wrap, love u bestie π«Άβ¨
π¦ where this page comes from
- fedora 44: libcurl-devel 8.18.0-14.fc44 Β· curl
- fedora 44: libcurl-devel 8.18.0-14.fc44 Β· curl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms