Curl not working

I am having trouble with Curl on PHP5, WAMP (php_curl is installed).

            $ch = curl_init();
	curl_setopt($ch, CURLOPT_URL, "");
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
	$out = curl_exec($ch);
	echo "<h1>OUT:".$out."</h1>";

This always returns nothing, no matter what URL I put in. I get no error messages.

works fine for me

Any idea why it would not be working on WAMP5?

Anyway to test that its installed correctly (although no errors suggests its installed ok)?

Try the following after the curl_exec():


I’d say it’s installed correctly, it just might be that your host is blocked from accessing Google. The information the above function returns will help you diagnose. If it isn’t installed then it’ll show nothing if you’ve completely suppressed all errors.

Check your firewall, does it allow apache for outgoing connections?

This is the result of print_r(curl_getinfo($ch));

[http_code] => 0 [header_size] => 0 [request_size] => 0 [filetime] => -1 [ssl_verify_result] => 0 [redirect_count] => 0 [total_time] => 0 [namelookup_time] => 0 [connect_time] => 0 [pretransfer_time] => 0 [size_upload] => 0 [size_download] => 0 [speed_download] => 0 [speed_upload] => 0 [download_content_length] => 0 [upload_content_length] => 0 [starttransfer_time] => 0 [redirect_time] => 0 )

I set error_reporting (E_ALL); at the top and get no errors.

If I try other URLs I also get blank response.

I cannot check firewall and am behind a company firewall. If I want to get it fixed what do I need to ask the Systems guys?

I’d say it is your firewall from that. As you can see from the lack of any connection details, the connection is not being made.

I asked Systems and they said they dont have a firewall, but a PROXY is used instead. They seem to be saying they cant do anything about it. Is it possible somehow to get Apache to get through the proxy?

It’s a tough one. Perhaps you can set the proxy they use in the proxy settings for cURL. CURLOPT_PROXY last time I checked, which can be used in conjunction with curl_setopt() function.

Im having fun now. Spent about 2 hours on this but can get any of those options to work.

Code is now like this, but I get a 403 error everytime from the proxy server:

		$url = "";
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL, $url);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
		curl_setopt($ch, CURLOPT_HEADER, 1); 
		curl_setopt($ch, CURLOPT_PROXY, ''); 			
		$out = curl_exec($ch);
		echo "<h2>Result</h2><p>".$out."</p>";


Adding this line tricks our proxy server into letting me through:

curl_setopt($ch, CURLOPT_USERAGENT, ‘Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv: Gecko/20071025 Firefox/’);

Hope this helps someone one day.