I've got a PHP script that utilizes cURL to gain access to personal files also situated on my small server (installed e-mail marketing program). I authored a fast script to check my cURL installation also it fails when pointed in a file by myself server. The script is:

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://www.mysite.com/test.php");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$contents = curl_exec($ch);

if($contents) {
    echo $contents;
} else {
    $err = curl_error($ch);
    echo $err;
}

curl_close($ch);

After I run this code, it returns a mistake: could not connect with host

Basically alter the Hyperlink to http://www.google.com or other site, it really works all right. Also, after i attempt to open the particular page via cURL on another server, it really works enjoy it should. The presumptions I am making from all of these tests would be that the PHP cURL is installed and (kinda) working which the issue is not within the page that's attempting to be opened up.

I figured it may be a port problem, and so i attempted indicating the main harbour with similar result (not hooking up to host). I attempted both curl_setopt and http://www.mysite.com:80/ to specify a port I understand to become open.

This leads me to think the problem is one thing during my apache installation, but I am no apache expert and I have been banging my mind against Google all day long with no success. Any ideas what might cause this type of specific cURL failure?

Are you able to ping www.mysite.com ?

Look at your /etc/hosts ... maybe there's an incorrect IP specified for www.mysite.com.

Attempt to open http://www.mysite.com/test.php inside a internet browser. Whether it works, then the issue is with cURL. Whether it does not, then the issue is either together with your network, or apache configuration.

You should check your apache configuration by ensuring it's running in your system. Then attempt to telnet <apache server ip> 80 in the command line. Once connected attempt to perform the following:

GET /test.php HTTP/1.1
Host: www.mysite.com
<2 line breaks>

When you get an answer from apache, it seems like a network problem. Make certain mysite.com resolves towards the Ip of the apache server, and port 80 traffic could possibly get for your server. It may be a loopback routing problem of the router attempting to make a request to it's own ip (presuming your apache box is behind a routed network connection, exactly the same connection that you're on).