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