php curl default timeout code example

Example 1: php curl timeout

curl_setopt($ch, CURLOPT_TIMEOUT, 5); //timeout in seconds
#curl_setopt($ch, CURLOPT_TIMEOUT_MS, 5000); //timeout in Milliseconds

Example 2: Curl default connect-timeout

The default connect timeout value seems to be 5 minutes / 300 seconds according to the DEFAULT_CONNECT_TIMEOUT macro in lib/connect.h.

On Debian it stops trying to connect after 2 minutes, regardless of the time specified with --connect-timeout 

A default value for --max-time doesn't seem to exist, making curl wait forever for a response if the initial connect succeeds.

curl has two options: --connect-timeout and --max-time.

Tags:

Php Example