tags:

views:

32

answers:

1

I have a CURL code that fetches some XML content from a remote server. I get the expected output on my localhost (XAMPP on windows). But from the live site(hosted on Linux), I get the CURL error:'couldn't connect to host'.

 function DownloadUrl($Url, $p){

// is curl installed? if (!function_exists('curl_init')){ die('CURL is not installed!'); }

   // create curl resource
    $ch = curl_init();

    // set url
    curl_setopt($ch, CURLOPT_URL, $Url);

curl_setopt ($ch, CURLOPT_POSTFIELDS, $p);
curl_setopt ($ch, CURLOPT_POST, 1);
    //return the transfer as a string
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

    // $output contains the output string
    $output = curl_exec($ch);

if($output === false)
 echo 'Curl error: ' . curl_error($ch);
else
  print $output;
    // close curl resource to free up system resources
    curl_close($ch);          

}

A: 

On you live server. run phpinfo(); and check to make sure php_curl is installed and active. This normally throws a fatal exception however rather than the "could not connect to host." message you are getting.

If you are still having problems, you may want to try a traceroute to teh URL through SSH to make sure the website can actually connect. There may be a configuration setting or other service that is causing issues.

Talvi Watia