PHP Curl cannot connect to host on own server

I have a PHP script that uses cURL to access a file that is also located on my server (installed email program). I wrote a quick script to check my cURL installation, and it does not work when it points to a file on my own server. script:

$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);

When I run this code, it returns an error: could not connect to the host

URL- http://www.google.com , . , cURL , , . , , , PHP cURL (kinda) , .

, , ( ). curl_setopt, http://www.mysite.com:80/ , , , .

, - - apache, apache, Google, . , cURL-?

+3
4

http://www.mysite.com/test.php -. , cURL. , , apache.

apache, , . telnet <apache server ip> 80 . :

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

apache, . , mysite.com IP- apache, 80 . , IP- (, Apache- , , ).

0

ping www.mysite.com?

/etc/hosts... , www.mysite.com IP-.

+1

, , CURL .

, - - ( -, ).

,

curl -I http://www.mywebserver.com :

$ curl -I http://www.mywebserver.com curl: (7) couldn't connect to host

/etc/hosts IP- , fopen CURL .

+1

-. curl , , apache . ,

curl -O http://example.com/file1.txt

curl -0 http://sub.example.com/file1.txt

.

, DNS DNS-, . , nslookup .. DNS-, - . DNS- " " curl, .

0

All Articles