[curl] Limit the time allowed for an HTTP request

Created on November 30, 2026

Use --max-time to set a transfer deadline in seconds. This example allows five seconds, including connection setup and data transfer.

curl --max-time 5 https://example.com/

curl returns exit status 28 when the deadline expires. Use --connect-timeout to limit the connection phase separately.

curl --connect-timeout 2 --max-time 5 https://example.com/

Here setup has a two-second limit and the whole transfer has a five-second limit. With retries, --max-time applies to each attempt. --retry-max-time controls how long curl keeps retrying.

Reference

Shell command curl