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