CURLOPT_MAXLIFETIME_CONN.md (1867B)
1 --- 2 c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. 3 SPDX-License-Identifier: curl 4 Title: CURLOPT_MAXLIFETIME_CONN 5 Section: 3 6 Source: libcurl 7 See-also: 8 - CURLOPT_FORBID_REUSE (3) 9 - CURLOPT_FRESH_CONNECT (3) 10 - CURLOPT_MAXAGE_CONN (3) 11 - CURLOPT_TIMEOUT (3) 12 Protocol: 13 - All 14 Added-in: 7.80.0 15 --- 16 17 # NAME 18 19 CURLOPT_MAXLIFETIME_CONN - max lifetime (since creation) allowed for reusing a connection 20 21 # SYNOPSIS 22 23 ~~~c 24 #include <curl/curl.h> 25 26 CURLcode curl_easy_setopt(CURL *handle, CURLOPT_MAXLIFETIME_CONN, 27 long maxlifetime); 28 ~~~ 29 30 # DESCRIPTION 31 32 Pass a long as parameter containing *maxlifetime* - the maximum time in 33 seconds, since the creation of the connection, that you allow an existing 34 connection to have to be considered for reuse for this request. 35 36 libcurl features a connection cache that holds previously used connections. 37 When a new request is to be done, libcurl considers any connection that 38 matches for reuse. The CURLOPT_MAXLIFETIME_CONN(3) limit prevents 39 libcurl from trying too old connections for reuse. This can be used for 40 client-side load balancing. If a connection is found in the cache that is 41 older than this set *maxlifetime*, it is instead marked for closure. 42 43 If set to 0, this behavior is disabled: all connections are eligible for reuse. 44 45 # DEFAULT 46 47 0 seconds (i.e., disabled) 48 49 # %PROTOCOLS% 50 51 # EXAMPLE 52 53 ~~~c 54 int 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 72 curl_easy_setopt(3) returns a CURLcode indicating success or error. 73 74 CURLE_OK (0) means everything was OK, non-zero means an error occurred, see 75 libcurl-errors(3).