PHP 5.2.6 + fsockopen on localhost

VirtualDarKness

Registered
Hello,
on a Mac OS X Server 10.5 with PHP 5.2.6 i've a problem with an old php script:

Warning: fsockopen() [function.fsockopen]: unable to connect to 127.0.0.1:80 (Connection refused) in /path/to/script.php on line 54


I've tried to write a test script with the followin code:

Code:
<?php
$fp = fsockopen("www.google.com", 80, $errno, $errstr, 30);
if (!$fp) {
    echo "$errstr ($errno)<br />\n";
} else {
    $out = "GET / HTTP/1.1\r\n";
    $out .= "Host: www.example.com\r\n";
    $out .= "Connection: Close\r\n\r\n";

    fwrite($fp, $out);
    while (!feof($fp)) {
        echo fgets($fp, 128);
    }
    fclose($fp);
}
?>

and it works correctly.. so the problems seems to happen when it tries to connect to localhost.

I've also tried to connect to 127.0.0.1 but got the same error.

any idea? should I change something in my php.ini?

thanks.

bye,
Giovanni.
 
/path/to/script.php
Is this line taken verbatim out of the script you're trying to run, or are you using it as an example?

The reason I ask is that it looks like you've used some sample code that somewhere says "path/to/script.php" -- which isn't actually a valid path -- it's an example that's meant to be replaced with the actual path to some script file.
 
Is this line taken verbatim out of the script you're trying to run, or are you using it as an example?

hi,
thanks for your answer.

I wrote it that way as an example..

bye,
Giovanni.

p.s.
anyway that was the path to the script that returned the error message, not the file the script were trying to access to.
 
Ok, so I assume the basics are covered: that you're actually running a web server on port 80 and it's properly configured, yes?

What happens if you use "localhost" instead of "127.0.0.1"? What happens if you use the FQD of the server?
 
Ok, so I assume the basics are covered: that you're actually running a web server on port 80 and it's properly configured, yes?

Yep, as I wrote I'm running Mac OS X Server 10.5 with PHP 5.2.6.

What happens if you use "localhost" instead of "127.0.0.1"?

I still get the Connection refused error. It looks like it can't connect to itself.. Searching on google I found it could be a firewall problem but does Mac OS X server have a pre-installed firewall?

What happens if you use the FQD of the server?

sorry.. what is the FQD? :p

thanks.

bye,
Giovanni.
 
Yes, both Mac OS X Client and Mac OS X Server come with a firewall -- in a default install, it's usually turned off, but you may want to check it. I would think that if you enabled Web Sharing that the proper ports would be automatically forwarded, but it never hurts to check:

http://www.apple.com/server/macosx/features/networking.html

FQD = "Fully Qualified Domain" -- i.e., "myserver.com" or something like that. Basically, the domain name one would use to connect to the server from the "outside" world. It could also be something like "serverone.local" or something -- whatever you set up the name of the server to be when you installed Mac OS X Server.
 
Back
Top