CURLMOPT_MAX_HOST_CONNECTIONS(3)

πŸ’… CURLMOPT_MAX_HOST_CONNECTIONS πŸ’…

okay so bestie, this page is from the libcurl corner of the Unix manual universe, and it's literally all about not letting libcurl go feral and open a million connections to the same host πŸŽ€


✨ NAME ✨

CURLMOPT_MAX_HOST_CONNECTIONS β€” the max number of connections to a single host, periodt πŸ’…


🌸 SYNOPSIS 🌸

#include <curl/curl.h>

CURLMcode curl_multi_setopt(CURLM *handle, CURLMOPT_MAX_HOST_CONNECTIONS,
                            long max);

πŸ¦‹ DESCRIPTION πŸ¦‹

So you pass a long in there to set max, and that's the maximum amount of simultaneously open connections libcurl may hold for a single host β€” and a "host" here is the same as a hostname + port number pair, iykyk 🫢

For every new transfer heading to that same host, libcurl might open a new connection up to the limit you set with CURLMOPT_MAX_HOST_CONNECTIONS(3). And when you hit the limit? New sessions just get kept pending until a connection becomes available. It's giving "we're at capacity, bestie, take a number" 😭

The default max value is 0, which means unlimited πŸ’€ This same limit also counts for proxy connections, and in that case the proxy is considered to be the host that this limit is counting against.

When you add more transfers to the multi handle than what can actually be performed because of the limit you set, they get queued up waiting for their chance ✨

⚠️ Real talk: while a transfer is queued up internally waiting for a connection, the CURLOPT_TIMEOUT_MS(3) timeout counts the waiting time inclusive, which means if you set too narrow a timeout the transfer might never even start before it times out 😭 Likewise the CURLOPT_CONNECTTIMEOUT_MS(3) time is still treated as a per-connect timeout and might expire even before making a new connection is permitted. No cap.

Changing this value while there are transfers in progress? Totally possible πŸŽ€ The new value is then used the next time checks are performed. And lowering the value does not close down any active transfers β€” it simply does not allow new ones to get made. Iconic behaviour honestly.


πŸ“ DEFAULT πŸ“

0


🌈 PROTOCOLS 🌈

This functionality affects all supported protocols πŸ’–


🧚 EXAMPLE 🧚

int main(void)
{
  CURLM *m = curl_multi_init();
  /* do no more than 2 connections per host */
  curl_multi_setopt(m, CURLMOPT_MAX_HOST_CONNECTIONS, 2L);
}

two per host and not one more, we're being responsible today girlies ✨


⭐ AVAILABILITY ⭐

Added in curl 7.30.0 πŸ‘‘


πŸ’œ RETURN VALUE πŸ’œ

curl_multi_setopt(3) returns a CURLMcode indicating success or error.

CURLM_OK (0) means everything was OK, non-zero means an error occurred β€” go check libcurl-errors(3) for the tea 🫢


πŸ”₯ SEE ALSO πŸ”₯


and that's the whole page, bestie 🌸 this one's from the libcurl manual, dated 2026-10-12, version libcurl β€” mwah, go forth and cap your connections responsibly πŸ’…πŸŽ€

πŸ“¦ where this page comes from