CURLMOPT_MAXCONNECTS(3)
π CURLMOPT_MAXCONNECTS π
okay bestie, so this one is from the libcurl manual β it's CURLMOPT_MAXCONNECTS(3), and it's the little knob that decides how big your connection cache gets to be. no cap, it's a good one to know π«Ά
β¨ NAME β¨
CURLMOPT_MAXCONNECTS β size of connection cache π
πΈ SYNOPSIS πΈ
#include <curl/curl.h>
CURLMcode curl_multi_setopt(CURLM *handle, CURLMOPT_MAXCONNECTS, long max);
π¦ DESCRIPTION π¦
so you pass a long in, and that's max β the maximum amount of connections libcurl is allowed to keep alive in its connection cache after it's done using them. iconic, right? π₯
by default, libcurl grows the size for every easy handle you add, so that it fits 4 times the number of added easy handles. (the way it just scales itself, honestly obsessed β¨)
the moment you set this option though, you're putting your foot down: the cache size is not allowed to grow beyond the limit you set. periodt.
and when the cache is full? curl closes the oldest connection in the cache so the number of connections can't sneak up. bye felicia to the oldest one π
quick heads-up, this is for the multi handle's use only. if you're on the easy interface instead, you want CURLOPT_MAXCONNECTS(3). don't mix them up bestie π
also β if you're actually trying to limit the number of active connections, that's a whole different vibe, go read CURLMOPT_MAX_TOTAL_CONNECTIONS(3).
changing this value while there are transfers in progress? totally possible π the new value just gets used the next time checks are performed. and lowering the value does not close down any active transfers β it simply doesn't allow new ones to get made. no drama, no cancellations π
π DEFAULT π
see DESCRIPTION (yes it's one of those, go look back up there β¬οΈ)
π§ PROTOCOLS π§
This functionality affects all supported protocols β every single one, we love an inclusive icon π
β EXAMPLE β
int main(void)
{
CURLM *m = curl_multi_init();
/* only keep 10 connections in the cache */
curl_multi_setopt(m, CURLMOPT_MAXCONNECTS, 10L);
}
look at that. ten connections max in the cache. slay π
π AVAILABILITY π
Added in curl 7.16.3 β a certified vintage classic at this point π
πΈ RETURN VALUE πΈ
curl_multi_setopt(3) returns a CURLMcode saying whether it succeeded or errored out.
CURLM_OK (0) means everything was OK π and non-zero means an error occurred β go check libcurl-errors(3) to find out what went wrong, iykyk π
π₯ SEE ALSO π₯
that's the whole page bestie, no notes π β¨ this was the libcurl version dated 2026-10-12 β go forth and cache responsibly π«Άπ
π¦ 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