The difference between curlopt_connecttimeout and curlopt_timeout in PHP curl

Source: Internet
Author: User
Tags curl php script

Today, I studied the Curl download parameters of PHP: Curlopt_connecttimeout and Curlopt_timeout differences:

Curlopt_connecttimeout

Tell the PHP script how long to wait before successfully connecting to the server, this parameter is to deal with the target server overload, offline, or crash and other possible conditions;

curl_setopt ($conn, curlopt_connecttimeout,10); , identify if the server does not respond within 10 seconds, the script will be disconnected;

Curlopt_timeout

Tells you how long the php script waits before the server receives a buffer to complete. This parameter can be useful if the target is a large file, the generated content is too slow, or the link is too slow.

curl_setopt ($conn, curlopt_timeout, 100); If the file to be downloaded is not downloaded within 100 seconds, the script will disconnect.


Curlopt_connecttimeout is used to tell the PHP script how long to wait before successfully connecting to the server (after the connection is successful, it will start buffering output), which is to deal with the possibility of overload, off-line, or crash of the target server.


Curlopt_timeout is used to tell a successful PHP script how long it will take to wait before the server receives a buffer to complete. This parameter can be useful if the target is a large file, the generated content is too slow, or the link is too slow.


Using Curl to download MP3 files is a good example for developers. Curlopt_connecttimeout
Can be set to 10 seconds, identifying if the server does not respond within 10 seconds, the script will disconnect, Curlopt_timeout can be set to 100, and if the MP3 file is not downloaded within 100 seconds, the script will disconnect.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.