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

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

问题描述

PHP 有这两个与超时相关的选项:CURLOPT_CONNECTTIMEOUTCURLOPT_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 向 URL 发送 GET vars 并且你想接收一个 XML,CURLOPT_CONNECTTIMEOUT 是否与它可以花费的最长时间有关连接到服务器和 CURLOPT_TIMEOUT 发送回 XML 所需的最长时间?

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 是允许连接到服务器的最长时间(以秒为单位).可以设置为 0 来禁用此限制,但在生产环境中这是不可取的.

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天全站免登陆