写了一个简单的curl请求
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_TIMEOUT_MS
PHP
cURL
的
超时
设置
有两个
CURL
OPT
_
CONNECT
TIMEOUT
和
CURL
OPT
_
TIMEOUT
,他们的区别是:
CURL
OPT
_
CONNECT
TIMEOUT
用来告诉
PHP
在成功连接服务器前等待多久(连接成功之后就会开始缓冲输出),这个参数是为了应对目标服务器的过载,下线,或者崩溃等可能状况。
CURL
OPT
_
TIMEOUT
用来告诉成功
PHP
从服务器接收缓冲完成前需要等待多长
时间
,如果目标是个巨大的文件,生成内容速度过慢或者链路速度过慢,这个参数就会很有用。
使用
cURL
..
CURL
OPT
_
CONNECT
TIMEOUT
:
The number of seconds to wait while trying to
connect
. Use 0 to wait indefinitely.
在尝试连接的时候等待的
秒
数。使用0无限期地等待。(即连接上服务器需要多长
时间
)
CURL
OPT
_
TIMEOUT
:
The maximum
There's a very distinctive difference between these two configurations within
cURL
. I'll try to define them for you, and then provide you
a very common example which I share to people who I teach ab
There's a very distinctive differencebetween
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 abou