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