1---
2c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
3SPDX-License-Identifier: curl
4Title: CURLOPT_MAXAGE_CONN
5Section: 3
6Source: libcurl
7See-also:
8  - CURLOPT_FORBID_REUSE (3)
9  - CURLOPT_FRESH_CONNECT (3)
10  - CURLOPT_MAXLIFETIME_CONN (3)
11  - CURLOPT_TIMEOUT (3)
12Protocol:
13  - All
14Added-in: 7.65.0
15---
16
17# NAME
18
19CURLOPT_MAXAGE_CONN - max idle time allowed for reusing a connection
20
21# SYNOPSIS
22
23~~~c
24#include <curl/curl.h>
25
26CURLcode curl_easy_setopt(CURL *handle, CURLOPT_MAXAGE_CONN, long age);
27~~~
28
29# DESCRIPTION
30
31Pass a long as parameter containing *age* - the maximum time in seconds
32allowed for an existing connection to have been idle to be considered for
33reuse for this request.
34
35The "connection cache" holds previously used connections. When a new request
36is to be done, libcurl considers any connection that matches for reuse. The
37CURLOPT_MAXAGE_CONN(3) limit prevents libcurl from trying too old
38connections for reuse, since old connections have a higher risk of not working
39and thus trying them is a performance loss and sometimes service loss due to
40the difficulties to figure out the situation. If a connection is found in the
41cache that is older than this set *age*, it is closed instead.
42
43# DEFAULT
44
45118 seconds
46
47# %PROTOCOLS%
48
49# EXAMPLE
50
51~~~c
52int 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
70Returns CURLE_OK.
71