Operations 4 min read

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.

ITPUB
ITPUB
ITPUB
Understanding curl’s Connection and Max‑Time Timeout Options

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/null

To 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 1

Key points

--connect-timeout

affects only the connection phase. -m/--max-time limits the whole operation.

Both options can be used together to protect scripts from hanging indefinitely.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

NetworkingcURLTimeoutcommand-line
ITPUB
Written by

ITPUB

Official ITPUB account sharing technical insights, community news, and exciting events.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.