CURLOPT_MAXLIFETIME_CONN.3 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. .\" **************************************************************************
  2. .\" * _ _ ____ _
  3. .\" * Project ___| | | | _ \| |
  4. .\" * / __| | | | |_) | |
  5. .\" * | (__| |_| | _ <| |___
  6. .\" * \___|\___/|_| \_\_____|
  7. .\" *
  8. .\" * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
  9. .\" *
  10. .\" * This software is licensed as described in the file COPYING, which
  11. .\" * you should have received as part of this distribution. The terms
  12. .\" * are also available at https://curl.se/docs/copyright.html.
  13. .\" *
  14. .\" * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  15. .\" * copies of the Software, and permit persons to whom the Software is
  16. .\" * furnished to do so, under the terms of the COPYING file.
  17. .\" *
  18. .\" * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  19. .\" * KIND, either express or implied.
  20. .\" *
  21. .\" * SPDX-License-Identifier: curl
  22. .\" *
  23. .\" **************************************************************************
  24. .\"
  25. .TH CURLOPT_MAXLIFETIME_CONN 3 "10 Nov 2021" libcurl libcurl
  26. .SH NAME
  27. CURLOPT_MAXLIFETIME_CONN \- max lifetime (since creation) allowed for reusing a connection
  28. .SH SYNOPSIS
  29. .nf
  30. #include <curl/curl.h>
  31. CURLcode curl_easy_setopt(CURL *handle, CURLOPT_MAXLIFETIME_CONN,
  32. long maxlifetime);
  33. .fi
  34. .SH DESCRIPTION
  35. Pass a long as parameter containing \fImaxlifetime\fP - the maximum time in
  36. seconds, since the creation of the connection, that you allow an existing
  37. connection to have to be considered for reuse for this request.
  38. libcurl features a connection cache that holds previously used connections.
  39. When a new request is to be done, it will consider any connection that matches
  40. for reuse. The \fICURLOPT_MAXLIFETIME_CONN(3)\fP limit prevents libcurl from
  41. trying too old connections for reuse. This can be used for client-side load
  42. balancing. If a connection is found in the cache that is older than this set
  43. \fImaxlifetime\fP, it will instead be closed once any in-progress transfers
  44. complete.
  45. If set to 0, this behavior is disabled: all connections are eligible for reuse.
  46. .SH DEFAULT
  47. Default \fImaxlifetime\fP is 0 seconds (i.e., disabled).
  48. .SH PROTOCOLS
  49. All
  50. .SH EXAMPLE
  51. .nf
  52. CURL *curl = curl_easy_init();
  53. if(curl) {
  54. curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
  55. /* only allow each connection to be reused for 30 seconds */
  56. curl_easy_setopt(curl, CURLOPT_MAXLIFETIME_CONN, 30L);
  57. curl_easy_perform(curl);
  58. }
  59. .fi
  60. .SH AVAILABILITY
  61. Added in 7.80.0
  62. .SH RETURN VALUE
  63. Returns CURLE_OK.
  64. .SH "SEE ALSO"
  65. .BR CURLOPT_TIMEOUT "(3), " CURLOPT_FORBID_REUSE "(3), "
  66. .BR CURLOPT_FRESH_CONNECT "(3), " CURLOPT_MAXAGE_CONN "(3), "