1--- 2c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. 3SPDX-License-Identifier: curl 4Title: CURLOPT_MAXLIFETIME_CONN 5Section: 3 6Source: libcurl 7See-also: 8 - CURLOPT_FORBID_REUSE (3) 9 - CURLOPT_FRESH_CONNECT (3) 10 - CURLOPT_MAXAGE_CONN (3) 11 - CURLOPT_TIMEOUT (3) 12Protocol: 13 - All 14Added-in: 7.80.0 15--- 16 17# NAME 18 19CURLOPT_MAXLIFETIME_CONN - max lifetime (since creation) allowed for reusing a connection 20 21# SYNOPSIS 22 23~~~c 24#include <curl/curl.h> 25 26CURLcode curl_easy_setopt(CURL *handle, CURLOPT_MAXLIFETIME_CONN, 27 long maxlifetime); 28~~~ 29 30# DESCRIPTION 31 32Pass a long as parameter containing *maxlifetime* - the maximum time in 33seconds, since the creation of the connection, that you allow an existing 34connection to have to be considered for reuse for this request. 35 36libcurl features a connection cache that holds previously used connections. 37When a new request is to be done, libcurl considers any connection that 38matches for reuse. The CURLOPT_MAXLIFETIME_CONN(3) limit prevents 39libcurl from trying too old connections for reuse. This can be used for 40client-side load balancing. If a connection is found in the cache that is 41older than this set *maxlifetime*, it is instead marked for closure. 42 43If set to 0, this behavior is disabled: all connections are eligible for reuse. 44 45# DEFAULT 46 470 seconds (i.e., disabled) 48 49# %PROTOCOLS% 50 51# EXAMPLE 52 53~~~c 54int main(void) 55{ 56 CURL *curl = curl_easy_init(); 57 if(curl) { 58 curl_easy_setopt(curl, CURLOPT_URL, "https://example.com"); 59 60 /* only allow each connection to be reused for 30 seconds */ 61 curl_easy_setopt(curl, CURLOPT_MAXLIFETIME_CONN, 30L); 62 63 curl_easy_perform(curl); 64 } 65} 66~~~ 67 68# %AVAILABILITY% 69 70# RETURN VALUE 71 72Returns CURLE_OK. 73