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, theCURLOPT_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 theCURLOPT_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
- 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