CURL:CONNECT后代理0代码? [英] CURL: Code 0 from proxy after CONNECT?

查看:286
本文介绍了CURL:CONNECT后代理0代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图测试下面的功能,但每次我尝试使用任何类型的代理IP(我已经尝试过 15 现在) - 我一般得到相同的错误:

 在CONNECT之后从代理接收到HTTP代码0 

这里是函数,有什么不对吗?它可能只是我使用的代理,但我已经尝试过几次现在。

  function getPage($ proxy,$ url, $ referer,$ agent,$ header,$ timeout){
$ ch = curl_init();
curl_setopt($ ch,CURLOPT_URL,$ url);
curl_setopt($ ch,CURLOPT_HEADER,$ header);
curl_setopt($ ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ ch,CURLOPT_PROXY,$ proxy);
curl_setopt($ ch,CURLOPT_HTTPPROXYTUNNEL,1);
curl_setopt($ ch,CURLOPT_CONNECTTIMEOUT,$ timeout);
curl_setopt($ ch,CURLOPT_REFERER,$ referer);
curl_setopt($ ch,CURLOPT_USERAGENT,$ agent);

$ result ['EXE'] = curl_exec($ ch);
$ result ['INF'] = curl_getinfo($ ch);
$ result ['ERR'] = curl_error($ ch);

curl_close($ ch);

return $ result;
}

一般来说,我可以改进吗?

$ b

我尝试另一个代理,它工作!



另一个问题仍然存在,我该如何改进上述。

解决方案

我知道你排序的回答你的第一个问题,但代码 0 不是有效的http状态代码。它们应以1(信息),2(成功),3(重定向),4(客户端错误)或5(服务器错误)开始。如果有人知道你为什么会得到这个代码,我会真的interseted。搜索 libcurl网站没有带来任何结果。



(如果您有兴趣,请点击此处查看详细信息:

http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.htmlt






对于第二个问题,我认为你需要找到最长的操作。 microtime()函数可能对你有用。 microtime()的文档有一些示例脚本来帮助您使用计时器。



我怀疑,虽然大多数3-4秒可能正在等待通过代理获得响应 curl_exe($ ch)


I am trying to test the below function but every time I try to use any sort of proxy IP (I have tried about 15 now) - I generally get the same error:

Received HTTP code 0 from proxy after CONNECT 

Here is the function, anything wrong with it? It could just be the proxies I am using but I have tried several times now.

function getPage($proxy, $url, $referer, $agent, $header, $timeout) {
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_HEADER, $header);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_PROXY, $proxy);
    curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
    curl_setopt($ch, CURLOPT_REFERER, $referer);
    curl_setopt($ch, CURLOPT_USERAGENT, $agent);

    $result['EXE'] = curl_exec($ch);
    $result['INF'] = curl_getinfo($ch);
    $result['ERR'] = curl_error($ch);

    curl_close($ch);

    return $result;
}

Also in general, anyway I can improve it?

I appreciate all help.

Update

As I submitted this, I tried another proxy and it worked!

The other question still stands, how can I improve the above. It takes about 3-4 seconds to execute, anything I can do, or is this too minimal?

解决方案

I know you sort of answered your first problem but code 0 is not a valid http status code. They should all begin with either 1 (informational), 2 (success), 3 (redirection), 4 (client error), or 5 (server error). I would be really interseted if anyone knows why you might get this code. Searching the libcurl site didn't bring anything up.

(More detailed information is here if you are interested:
http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.htmlt)


For the second question I think you would need to find where the longest operation was.The microtime() function might be useful to you here. The documentation for microtime() has some example scripts to help you use the timer.

I suspect though that most of the 3-4 seconds could be waiting to get the response via the proxy at curl_exe($ch).

这篇关于CURL:CONNECT后代理0代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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