PHP cURL:CURLOPT_CONNECTTIMEOUT与CURLOPT_TIMEOUT [英] PHP cURL: CURLOPT_CONNECTTIMEOUT vs CURLOPT_TIMEOUT

查看:330
本文介绍了PHP cURL:CURLOPT_CONNECTTIMEOUT与CURLOPT_TIMEOUT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

PHP有两个与超时相关的选项: CURLOPT_CONNECTTIMEOUT CURLOPT_TIMEOUT

PHP has these two options related to timeout: CURLOPT_CONNECTTIMEOUT and CURLOPT_TIMEOUT.

PHP网站上的描述有点含糊。有什么区别?

The descriptions on the PHP site are a bit vague. What's the difference?

要使用一个真实世界的例子:假设你通过cURL发送GET vars到一个URL,你想接收一个XML, c $ c> CURLOPT_CONNECTTIMEOUT 与连接到服务器可以花费的最大时间有关,而 CURLOPT_TIMEOUT 可以占用的最大时间

To use a real world example: say you're sending GET vars to a URL via cURL and you want to receive a XML back, would CURLOPT_CONNECTTIMEOUT relate to the maximum amount of time it can take to connect to the server and CURLOPT_TIMEOUT the maximum amount of time it can take to send the XML back?

推荐答案


CURLOPT_CONNECTTIMEOUT是允许的最大时间以连接到服务器。

CURLOPT_CONNECTTIMEOUT is the maximum amount of time in seconds that is allowed to make the connection to the server. It can be set to 0 to disable this limit, but this is inadvisable in a production environment.

CURLOPT_TIMEOUT是以秒为单位的最大时间,以秒为单位。各个cURL扩展函数调用的执行将受到限制。
请注意,此设置的值应包含CURLOPT_CONNECTTIMEOUT的值。

CURLOPT_TIMEOUT is a maximum amount of time in seconds to which the execution of individual cURL extension function calls will be limited. Note that the value for this setting should include the value for CURLOPT_CONNECTTIMEOUT.

换句话说,
CURLOPT_CONNECTTIMEOUT是由CURLOPT_TIMEOUT,因此CURLOPT_TIMEOUT的值应大于CURLOPT_CONNECTTIMEOUT的值。

In other words, CURLOPT_CONNECTTIMEOUT is a segment of the time represented by CURLOPT_TIMEOUT, so the value of the CURLOPT_TIMEOUT should be greater than the value of the CURLOPT_CONNECTTIMEOUT.

CURLOPT_CONNECTTIMEOUT和CURLOPT_TIMEOUT之间的差异

这篇关于PHP cURL:CURLOPT_CONNECTTIMEOUT与CURLOPT_TIMEOUT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆