CURLOPT_MAXLIFETIME_CONN.3 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. .\" generated by cd2nroff 0.1 from CURLOPT_MAXLIFETIME_CONN.md
  2. .TH CURLOPT_MAXLIFETIME_CONN 3 "2025-01-17" libcurl
  3. .SH NAME
  4. CURLOPT_MAXLIFETIME_CONN \- max lifetime (since creation) allowed for reusing a connection
  5. .SH SYNOPSIS
  6. .nf
  7. #include <curl/curl.h>
  8. CURLcode curl_easy_setopt(CURL *handle, CURLOPT_MAXLIFETIME_CONN,
  9. long maxlifetime);
  10. .fi
  11. .SH DESCRIPTION
  12. Pass a long as parameter containing \fImaxlifetime\fP \- the maximum time in
  13. seconds, since the creation of the connection, that you allow an existing
  14. connection to have to be considered for reuse for this request.
  15. libcurl features a connection cache that holds previously used connections.
  16. When a new request is to be done, libcurl considers any connection that
  17. matches for reuse. The \fICURLOPT_MAXLIFETIME_CONN(3)\fP limit prevents
  18. libcurl from trying too old connections for reuse. This can be used for
  19. client\-side load balancing. If a connection is found in the cache that is
  20. older than this set \fImaxlifetime\fP, it is instead marked for closure.
  21. If set to 0, this behavior is disabled: all connections are eligible for reuse.
  22. .SH DEFAULT
  23. 0 seconds (i.e., disabled)
  24. .SH PROTOCOLS
  25. This functionality affects all supported protocols
  26. .SH EXAMPLE
  27. .nf
  28. int main(void)
  29. {
  30. CURL *curl = curl_easy_init();
  31. if(curl) {
  32. curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
  33. /* only allow each connection to be reused for 30 seconds */
  34. curl_easy_setopt(curl, CURLOPT_MAXLIFETIME_CONN, 30L);
  35. curl_easy_perform(curl);
  36. }
  37. }
  38. .fi
  39. .SH AVAILABILITY
  40. Added in curl 7.80.0
  41. .SH RETURN VALUE
  42. Returns CURLE_OK.
  43. .SH SEE ALSO
  44. .BR CURLOPT_FORBID_REUSE (3),
  45. .BR CURLOPT_FRESH_CONNECT (3),
  46. .BR CURLOPT_MAXAGE_CONN (3),
  47. .BR CURLOPT_TIMEOUT (3)