Friday, December 16, 2011

PHP Curl not working on GoDaddy Host : why and Solution

Problem is that sometimes PHP Curl library not works on GoDaddy Host. Why curl is not working and how to solve this issue is what this post is all about.

I was trying to use curl library in my php code. But was soon tired of seeing numerous failures. My code was pretty much neet [those who know me know that well. I like cleanliness!! ;) ].

Still I was getting timeouts or some or the other errors , as I tried playing between parametrs. It was after some research over the internet and the manual, I found out that the trouble was because of host. Actually, GoDaddy uses a proxy server.

Voila!! You got it!!

So now on, if anyone uses GoDaddy as host and wants to use the curl library in his codes, has to just tweak his code by some additional lines.

Let us assume that $hn is the curl handler.
Then you have to include this line in your PHP Code---
curl_setopt($hn, CURLOPT_PROXY,"");

Lets see an example..

$url = "";

$hn = curl_init();
curl_setopt ($hn, CURLOPT_URL, $url);
curl_setopt ($hn, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($hn, CURLOPT_PROXY,"");
curl_setopt ($hn, CURLOPT_TIMEOUT, 120);
$res = curl_exec ($hn);
if(is_int($res)) {
die("Error occured: " . curl_errno($hn) . " : " . curl_error($hn));
curl_close ($hn);

print "Target URL: " . $url . " " . $res;

Now, you may as thanks click on few of the advertisements links. Do it man!!

1 comment:

  1. The Haryana Police exam is expected to be held in Feb 2017. The Haryana Police Exam date will be announced soon