PROXY use with PHP Curl/file_get_contents

lanbo

Elite Member
Jr. VIP
Premium Member
Joined
Aug 23, 2009
Messages
4,500
Reaction score
677
here:

PHP:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://www.example.com');
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1);
curl_setopt($ch, CURLOPT_PROXY, 'fakeproxy.com:1080');
curl_setopt($ch, CURLOPT_PROXYUSERPWD, 'user:password');
$data = curl_exec();
curl_close($ch);


if you get error "HTTP/1.0 405 Method Not Allowed"
try to change
PHP:
curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 0);

now give me some rep :P
 
Anyone know and tested a working php curl/file_get_contents script that has proxy support?

I tried this script:
http://www.higherpass.com/php/tutorials/Using-Curl-To-Query-Remote-Servers/3/

And I get this error:

Warning: file_get_contents(http://google.com/) [function.file-get-contents]: failed to open stream: Connection refused in /home/user/public_html/test.php on line 10

Any ideas? Proxy is working fine, verified

I'm not entirely sure (can't remember) but that may be the error returned when allow_url_fopen is set to off in your php.ini. To test this I would just run a php file containing the function phpinfo(); on your server.

You should definitely use cURL (functionality aside - it proves the faster data retriever with all benchmarks I've seen so far) as per the above poster, but I just thought I'd give some insight as to why your file_get_contents() request may be failing.
 
Back
Top