0

I've asked my host plenty of times now if this was on their side, and they said no. Everything in cURL is working/enabled; however, whenever I try the below code, I can never get a connection or page returned (I've tested many differnet working proxies).

<?php

//THIS IS A TEST
$ch = curl_init('http://www.google.com');
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:14.0) Gecko/20100101 Firefox/14.0.1');
curl_setopt($ch, CURLOPT_PROXY, '114.80.136.112:7780');
curl_setopt($ch, CURLOPT_TIMEOUT, 40);
curl_exec($ch);
echo curl_error($ch);
print_r(curl_getinfo($ch));
curl_close($ch);

?>

Can anyone else test this function for me and see if they get any working results?

EDIT: HAVE ALSO TRIED

<?php

//THIS IS A TEST
$ch = curl_init('http://www.google.com');

$f = fopen('requests.txt', 'w');

curl_setopt_array($ch, array(
    CURLOPT_PROXY => '114.80.136.112:7780',
    CURLOPT_PROXYTYPE => CURLPROXY_HTTP,
    CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:14.0) Gecko/20100101 Firefox/14.0.1',
    CURLOPT_TIMEOUT => 40,
    CURLOPT_VERBOSE        => 1,
    CURLOPT_STDERR         => $f,
));

curl_exec($ch);
fclose($f);
echo curl_error($ch);
print_r(curl_getinfo($ch));
curl_close($ch);

?>

That returned this in results.txt

* About to connect() to proxy 114.80.136.112 port 7780 (#0)
*   Trying 114.80.136.112...
* Timeout
* connect() timed out!
* Closing connection #0
Justin
  • 409
  • 2
  • 8
  • 14

2 Answers2

0

Return

<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>302 Moved</TITLE></HEAD><BODY>
<H1>302 Moved</H1>
The document has moved
<A HREF="http://www.google.com.hk/url?sa=p&amp;hl=zh-CN&amp;pref=hkredirect&amp;pval=yes&amp;q=http://www.google.com.hk/&amp;ust=1373746017821152&amp;usg=AFQjCNG2MqAeEfu9C9h5dmJu1n0YZWm5vw">here</A>.
</BODY></HTML>
Array
(
    [url] => http://www.google.com
    [content_type] => text/html; charset=UTF-8
    [http_code] => 302
    [header_size] => 580
    [request_size] => 191
    [filetime] => -1
    [ssl_verify_result] => 0
    [redirect_count] => 0
    [total_time] => 0.733
    [namelookup_time] => 0
    [connect_time] => 0.328
    [pretransfer_time] => 0.328
    [size_upload] => 0
    [size_download] => 376
    [speed_download] => 512
    [speed_upload] => 0
    [download_content_length] => 376
    [upload_content_length] => 0
    [starttransfer_time] => 0.733
    [redirect_time] => 0
    [certinfo] => Array
        (
        )

    [redirect_url] => http://www.google.com.hk/url?sa=p&hl=zh-CN&pref=hkredirect&pval=yes&q=http://www.google.com.hk/&ust=1373746017821152&usg=AFQjCNG2MqAeEfu9C9h5dmJu1n0YZWm5vw
)

try check curl in phpinfo();

Nano
  • 1
  • If it helps, here's some pictures of my phpinfo() output related to cURL. http://puu.sh/3C6EZ && http://puu.sh/3C6Ew – Justin Jul 13 '13 at 20:22
0

You may need to set your PROXY TYPE as well:

curl_setopt( $curl_handle, CURLOPT_PROXY, '127.0.0.1:9050' );
curl_setopt( $curl_handle, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5 );

Also, for debugging, fiddler is invaluable. With it, you can craft HTTP requests (even to a service using HTTPS) to troubleshoot a remote service.

You should be able to generate the full request message that is sent by curl to your proxy by using this method.

Lastly, though this may not help you in this case, I wrote a standalone curl wrapper class in PHP. Adding methods to it or using as is my make it a bit easier to work with curl.

https://github.com/homer6/altumo/blob/master/source/php/Http/OutgoingHttpRequest.md

https://github.com/homer6/altumo/blob/master/source/php/Http/OutgoingHttpRequest.php

Community
  • 1
  • 1
Homer6
  • 15,034
  • 11
  • 61
  • 81
  • Yeah, I just tried setting the PROXYTYPE to HTTP, yet it's still not returning anything. I've updated the OP to show the code I tried and results with your suggested method. – Justin Jul 13 '13 at 20:32