Understanding curl’s Connection and Max‑Time Timeout Options
This article explains curl’s two timeout settings—--connect-timeout for limiting the connection phase and -m/--max-time for restricting the total operation—provides error examples, and shows practical command-line usages to prevent hanging processes.
Background
While monitoring a server, the author noticed a curl process that had been running for 28 days, which seemed abnormal.
Understanding curl timeout options
curl provides two distinct timeout settings. --connect-timeout limits only the time spent establishing the connection to the server. If the connection cannot be made within the specified seconds, curl aborts with an error like curl: (28) connect() timed out!.
The -m or --max-time option sets the maximum total time allowed for the entire operation, including DNS resolution, connection, data transfer, and any redirects. When this limit is exceeded, curl reports an error such as
curl: (28) Operation timed out after 2000 milliseconds with 0 bytes received.
Practical examples
To limit only the connection phase to five seconds while sending data:
curl --connect-timeout 5 --data-binary "set=${L_UPLOAD_DATA_ENCODED}" http://172.88.99.00:8080/xxx.php >/dev/nullTo abort a download if the transfer speed falls below 1 byte per second for more than five seconds:
curl -o x.log "http://www.yyyy.com" --speed-time 5 --speed-limit 1Key points
--connect-timeoutaffects only the connection phase. -m/--max-time limits the whole operation.
Both options can be used together to protect scripts from hanging indefinitely.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
ITPUB
Official ITPUB account sharing technical insights, community news, and exciting events.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
