CURLOPT_VERBOSE解释说,系统在实际向Web链接发出请求之前需要时间连接到PROXY。
$ch = curl_init("$url");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 0);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_ENCODING, "gzip");
curl_setopt($ch, CURLOPT_PROXY, "$ip");
curl_setopt($ch, CURLOPT_PROXYPORT, "$po");
$response = curl_exec($ch);
$errmsg = curl_error($ch);
$cInfo = curl_getinfo($ch);
curl_close($ch);
我想在不关闭curl的情况下执行多个链接以减少延迟。有没有办法让PROXY保持直播并对链接做多个请求?
答案 0 :(得分:0)
当curl使用代理时,连接将保持打开状态,直到调用curl_close。
两个要点,
举个例子:
//$ch = curl_init("$url");
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 0);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_ENCODING, "gzip");
curl_setopt($ch, CURLOPT_PROXY, "$ip");
curl_setopt($ch, CURLOPT_PROXYPORT, "$po");
curl_setopt($context, CURLOPT_URL, $url); // Request One
$response = curl_exec($ch);
$errmsg = curl_error($ch);
$cInfo = curl_getinfo($ch);
curl_setopt($context, CURLOPT_URL, $url); // Request Two
$response = curl_exec($ch);
$errmsg = curl_error($ch);
$cInfo = curl_getinfo($ch);
curl_setopt($context, CURLOPT_URL, $url); // Request Three
$response = curl_exec($ch);
$errmsg = curl_error($ch);
$cInfo = curl_getinfo($ch);
curl_close($ch); //Closing after all requests
第一个请求需要一些时间才能建立到代理的连接,这取决于多个因素。在第一个请求之后,所有请求将更快并且将基于实际代理速度(提供的服务器脚本> =代理速度)发生。
我认为我们无法进行持久连接。如果您知道如何操作,请分享:-)