I am using fopen to open a URL from my site to another site that hosts .xml data.

I receive this error: failed to open stream: Connection refused

Now the target site is a website that is on port 8080, so could this be a problem with my host not allowing the connection to that, or the destination site refusing the connection?

If I enter the URL in my browers, the xml data shows up fine, so I am assuming my Host is refusing the connection.

Sound logical?

    If the objective is just to grab that XML text, you could use file_get_contents():

    $xmlData = file_get_contents("http://www.site.com/data.xml");
    if($xmlData === FALSE)
    {
       user_error("Unable to get XML data", E_USER_WARNING);
    }
    

      Thanks for the reply. How is file_get_contents different than fopen?

        It just combines everything into one command instead of having to do fopen(), a loop on fgets(), then a fclose(). However, if...

        $fh = fopen("http://www.site.com/data.xml", "r");

        ...does not work, then I would not expect file_get_contents() to the same URL to work, either.

          My webhost appears to be blocking port 8080.

          But I did try your command Nog, and I actually like it better, thanks for the tip.

            Write a Reply...