简体   繁体   English

CURL:CONNECT后来自代理的代码0?

[英]CURL: Code 0 from proxy after CONNECT?

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: 我正在尝试测试以下功能,但是每次尝试使用任何种类的代理IP(我现在尝试使用大约15种 )时,我通常都会遇到相同的错误:

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? 执行大约需要3-4秒,我可以做任何事情,还是这太少了?

I know you sort of answered your first problem but code 0 is not a valid http status code. 我知道您已经回答了第一个问题,但是代码0不是有效的http状态代码。 They should all begin with either 1 (informational), 2 (success), 3 (redirection), 4 (client error), or 5 (server error). 它们都应以1(信息性),2(成功),3(重定向),4(客户端错误)或5(服务器错误)开头。 I would be really interseted if anyone knows why you might get this code. 如果有人知道您为什么会获得此代码,我将真的很困惑。 Searching the libcurl site didn't bring anything up. 搜索libcurl网站没有显示任何内容。

(More detailed information is here if you are interested: (如果您有兴趣,可以在这里找到更多详细信息:
http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.htmlt ) 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. 对于第二个问题,我认为您需要找到最长的操作在哪里。在这里microtime()函数可能对您有用。 The documentation for microtime() has some example scripts to help you use the timer. microtime()文档提供了一些示例脚本来帮助您使用计时器。

I suspect though that most of the 3-4 seconds could be waiting to get the response via the proxy at curl_exe($ch) . 我怀疑尽管这3-4秒中的大部分时间可能都在等待通过curl_exe($ch)上的代理获得响应。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM