CURLOPT_MAXAGE_CONN.md (1730B)
1 --- 2 c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. 3 SPDX-License-Identifier: curl 4 Title: CURLOPT_MAXAGE_CONN 5 Section: 3 6 Source: libcurl 7 See-also: 8 - CURLOPT_FORBID_REUSE (3) 9 - CURLOPT_FRESH_CONNECT (3) 10 - CURLOPT_MAXLIFETIME_CONN (3) 11 - CURLOPT_TIMEOUT (3) 12 Protocol: 13 - All 14 Added-in: 7.65.0 15 --- 16 17 # NAME 18 19 CURLOPT_MAXAGE_CONN - max idle time 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_MAXAGE_CONN, long age); 27 ~~~ 28 29 # DESCRIPTION 30 31 Pass a long as parameter containing *age* - the maximum time in seconds 32 allowed for an existing connection to have been idle to be considered for 33 reuse for this request. 34 35 The "connection cache" holds previously used connections. When a new request 36 is to be done, libcurl considers any connection that matches for reuse. The 37 CURLOPT_MAXAGE_CONN(3) limit prevents libcurl from trying too old 38 connections for reuse, since old connections have a higher risk of not working 39 and thus trying them is a performance loss and sometimes service loss due to 40 the difficulties to figure out the situation. If a connection is found in the 41 cache that is older than this set *age*, it is closed instead. 42 43 # DEFAULT 44 45 118 seconds 46 47 # %PROTOCOLS% 48 49 # EXAMPLE 50 51 ~~~c 52 int main(void) 53 { 54 CURL *curl = curl_easy_init(); 55 if(curl) { 56 curl_easy_setopt(curl, CURLOPT_URL, "https://example.com"); 57 58 /* only allow 30 seconds idle time */ 59 curl_easy_setopt(curl, CURLOPT_MAXAGE_CONN, 30L); 60 61 curl_easy_perform(curl); 62 } 63 } 64 ~~~ 65 66 # %AVAILABILITY% 67 68 # RETURN VALUE 69 70 curl_easy_setopt(3) returns a CURLcode indicating success or error. 71 72 CURLE_OK (0) means everything was OK, non-zero means an error occurred, see 73 libcurl-errors(3).