tags:

views:

183

answers:

1

Hello all,

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?

+1  A: 

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), $ (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).

bearver