xref: /curl/docs/libcurl/opts/CURLOPT_TIMEOUT.md (revision f81f351b)
1---
2c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
3SPDX-License-Identifier: curl
4Title: CURLOPT_TIMEOUT
5Section: 3
6Source: libcurl
7See-also:
8  - CURLOPT_CONNECTTIMEOUT (3)
9  - CURLOPT_LOW_SPEED_LIMIT (3)
10  - CURLOPT_TCP_KEEPALIVE (3)
11  - CURLOPT_TIMEOUT_MS (3)
12Protocol:
13  - All
14Added-in: 7.1
15---
16
17# NAME
18
19CURLOPT_TIMEOUT - maximum time the transfer is allowed to complete
20
21# SYNOPSIS
22
23~~~c
24#include <curl/curl.h>
25
26CURLcode curl_easy_setopt(CURL *handle, CURLOPT_TIMEOUT, long timeout);
27~~~
28
29# DESCRIPTION
30
31Pass a long as parameter containing *timeout* - the maximum time in
32seconds that you allow the entire transfer operation to take. The whole thing,
33from start to end. Normally, name lookups can take a considerable time and
34limiting operations risk aborting perfectly normal operations.
35
36CURLOPT_TIMEOUT_MS(3) is the same function but set in milliseconds.
37
38If both CURLOPT_TIMEOUT(3) and CURLOPT_TIMEOUT_MS(3) are set, the
39value set last is used.
40
41Since this option puts a hard limit on how long time a request is allowed to
42take, it has limited use in dynamic use cases with varying transfer
43times. That is especially apparent when using the multi interface, which may
44queue the transfer, and that time is included. You are advised to explore
45CURLOPT_LOW_SPEED_LIMIT(3), CURLOPT_LOW_SPEED_TIME(3) or using
46CURLOPT_PROGRESSFUNCTION(3) to implement your own timeout logic.
47
48The connection timeout set with CURLOPT_CONNECTTIMEOUT(3) is included in
49this general all-covering timeout.
50
51With CURLOPT_CONNECTTIMEOUT(3) set to 3 and CURLOPT_TIMEOUT(3) set
52to 5, the operation can never last longer than 5 seconds.
53
54With CURLOPT_CONNECTTIMEOUT(3) set to 4 and CURLOPT_TIMEOUT(3) set
55to 2, the operation can never last longer than 2 seconds.
56
57This option may cause libcurl to use the SIGALRM signal to timeout system
58calls on builds not using asynch DNS. In Unix-like systems, this might cause
59signals to be used unless CURLOPT_NOSIGNAL(3) is set.
60
61# DEFAULT
62
630 (zero) which means it never times out during transfer.
64
65# %PROTOCOLS%
66
67# EXAMPLE
68
69~~~c
70int main(void)
71{
72  CURL *curl = curl_easy_init();
73  if(curl) {
74    curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
75
76    /* complete within 20 seconds */
77    curl_easy_setopt(curl, CURLOPT_TIMEOUT, 20L);
78
79    curl_easy_perform(curl);
80  }
81}
82~~~
83
84# %AVAILABILITY%
85
86# RETURN VALUE
87
88Returns CURLE_OK. Returns CURLE_BAD_FUNCTION_ARGUMENT if set to a negative
89value or a value that when converted to milliseconds is too large.
90