1CURLOPT_TIMEOUT_MS(3) curl_easy_setopt options CURLOPT_TIMEOUT_MS(3)
2
3
4
6 CURLOPT_TIMEOUT_MS - maximum time the transfer is allowed to complete
7
9 #include <curl/curl.h>
10
11 CURLcode curl_easy_setopt(CURL *handle, CURLOPT_TIMEOUT_MS, long timeout);
12
14 Pass a long as parameter containing timeout - the maximum time in mil‐
15 liseconds that you allow the libcurl transfer operation to take. Nor‐
16 mally, name lookups can take a considerable time and limiting opera‐
17 tions to less than a few minutes risk aborting perfectly normal opera‐
18 tions. This option may cause libcurl to use the SIGALRM signal to time‐
19 out system calls.
20
21 If libcurl is built to use the standard system name resolver, that por‐
22 tion of the transfer will still use full-second resolution for timeouts
23 with a minimum timeout allowed of one second.
24
25 In unix-like systems, this might cause signals to be used unless CUR‐
26 LOPT_NOSIGNAL(3) is set.
27
28 If both CURLOPT_TIMEOUT(3) and CURLOPT_TIMEOUT_MS(3) are set, the value
29 set last will be used.
30
31 Since this puts a hard limit for how long time a request is allowed to
32 take, it has limited use in dynamic use cases with varying transfer
33 times. You are then advised to explore CURLOPT_LOW_SPEED_LIMIT(3), CUR‐
34 LOPT_LOW_SPEED_TIME(3) or using CURLOPT_PROGRESSFUNCTION(3) to imple‐
35 ment your own timeout logic.
36
38 Default timeout is 0 (zero) which means it never times out during
39 transfer.
40
42 All
43
45 CURL *curl = curl_easy_init();
46 if(curl) {
47 curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
48
49 /* complete within 20000 milliseconds */
50 curl_easy_setopt(curl, CURLOPT_TIMEOUT_MS, 20000L);
51
52 curl_easy_perform(curl);
53 }
54
56 Always
57
59 Returns CURLE_OK
60
62 CURLOPT_TIMEOUT(3), CURLOPT_CONNECTTIMEOUT(3), CUR‐
63 LOPT_LOW_SPEED_LIMIT(3),
64
65
66
67libcurl 7.85.0 May 17, 2022 CURLOPT_TIMEOUT_MS(3)