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