CURLOPT_CONNECTTIMEOUT 和 CURLOPT_TIMEOUT的区别

There's a very distinctive difference between these two configurations within cURL. I'll try to definethemfor you, and then provide you a very common example which I shareto people who I teach about cURL.

CURLOPT_CONNECTTIMEOUT is designed to tell the script how long to wait to make a successful connection to the server before starting to buffer the output. Adestination's server which may be overloaded, offline or crashedwould probably make this setting becomeuseful.

CURLOPT_TIMEOUT isdesigned to tell the script how long to wait to receive acompletely buffered output from the server. A destination's hugefile, slow connection speeds or slow rendering would probably makethis setting become useful.

A good example of where these will both apply to, is when you'retelling cURL to download a MP3 file. CURLOPT_CONNECTTIMEOUT would be set at about 10 seconds which would mean that if no response is provided within 10 seconds then the script will abort, and CURLOPT_TIMEOUT would be set at about 100 seconds which would mean if the MP3 has not downloaded within 100 seconds then abort the script. It's the best way of explaining it to developers.

CURLOPT_CONNECTTIMEOUT:服务器没有相应的超时时间。

CURLOPT_TIMEOUT:服务器连接的超时时间。

最近性能优化中,发现接口请求有的会长达3s,检查框架代码后发现是由于没有设置超时时间导致。

相关资料:
What the different CURLOPT_CONNECTTIMEOUT and CURLOPT_TIMEOUT

标签: none

添加新评论