CURLOPT_TIMEOUT.3 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. .\" generated by cd2nroff 0.1 from CURLOPT_TIMEOUT.md
  2. .TH CURLOPT_TIMEOUT 3 "2025-01-17" libcurl
  3. .SH NAME
  4. CURLOPT_TIMEOUT \- maximum time the transfer is allowed to complete
  5. .SH SYNOPSIS
  6. .nf
  7. #include <curl/curl.h>
  8. CURLcode curl_easy_setopt(CURL *handle, CURLOPT_TIMEOUT, long timeout);
  9. .fi
  10. .SH DESCRIPTION
  11. Pass a long as parameter containing \fItimeout\fP \- the maximum time in
  12. seconds that you allow the entire transfer operation to take. The whole thing,
  13. from start to end. Normally, name lookups can take a considerable time and
  14. limiting operations risk aborting perfectly normal operations.
  15. \fICURLOPT_TIMEOUT_MS(3)\fP is the same function but set in milliseconds.
  16. If both \fICURLOPT_TIMEOUT(3)\fP and \fICURLOPT_TIMEOUT_MS(3)\fP are set, the
  17. value set last is used.
  18. Since this option puts a hard limit on how long time a request is allowed to
  19. take, it has limited use in dynamic use cases with varying transfer
  20. times. That is especially apparent when using the multi interface, which may
  21. queue the transfer, and that time is included. You are advised to explore
  22. \fICURLOPT_LOW_SPEED_LIMIT(3)\fP, \fICURLOPT_LOW_SPEED_TIME(3)\fP or using
  23. \fICURLOPT_PROGRESSFUNCTION(3)\fP to implement your own timeout logic.
  24. The connection timeout set with \fICURLOPT_CONNECTTIMEOUT(3)\fP is included in
  25. this general all\-covering timeout.
  26. With \fICURLOPT_CONNECTTIMEOUT(3)\fP set to 3 and \fICURLOPT_TIMEOUT(3)\fP set
  27. to 5, the operation can never last longer than 5 seconds.
  28. With \fICURLOPT_CONNECTTIMEOUT(3)\fP set to 4 and \fICURLOPT_TIMEOUT(3)\fP set
  29. to 2, the operation can never last longer than 2 seconds.
  30. This option may cause libcurl to use the SIGALRM signal to timeout system
  31. calls on builds not using asynch DNS. In unix\-like systems, this might cause
  32. signals to be used unless \fICURLOPT_NOSIGNAL(3)\fP is set.
  33. .SH DEFAULT
  34. 0 (zero) which means it never times out during transfer.
  35. .SH PROTOCOLS
  36. This functionality affects all supported protocols
  37. .SH EXAMPLE
  38. .nf
  39. int main(void)
  40. {
  41. CURL *curl = curl_easy_init();
  42. if(curl) {
  43. curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
  44. /* complete within 20 seconds */
  45. curl_easy_setopt(curl, CURLOPT_TIMEOUT, 20L);
  46. curl_easy_perform(curl);
  47. }
  48. }
  49. .fi
  50. .SH AVAILABILITY
  51. Added in curl 7.1
  52. .SH RETURN VALUE
  53. Returns CURLE_OK. Returns CURLE_BAD_FUNCTION_ARGUMENT if set to a negative
  54. value or a value that when converted to milliseconds is too large.
  55. .SH SEE ALSO
  56. .BR CURLOPT_CONNECTTIMEOUT (3),
  57. .BR CURLOPT_LOW_SPEED_LIMIT (3),
  58. .BR CURLOPT_TCP_KEEPALIVE (3),
  59. .BR CURLOPT_TIMEOUT_MS (3)