You are here:  » fopen() through firewall


fopen() through firewall

Submitted by cesare on Mon, 2006-07-24 11:50 in

Hello,
I purchased MagicParser and I have a problem using it on my server.
I have the following feed located at http://www.ziogiorgio.it/rss_feed.xml
I cut and pasted the code suggested at your demo page and the page hangs when I run it on my server.
I have no problems with the script if I put the feed text file directly into the same directory...
Any hint?
Thank you,
Cesare

p.s.: the allow_url is enabled on php.ini

Submitted by support on Mon, 2006-07-24 12:31

Hello Cesare,

It does sound like fopen() is not working with a URL on your server. Can you try running a test script to see what is happening. Something like the following:

<?php
  $url 
"http://www.ziogiorgio.it/rss_feed.xml";
  
$file fopen($url,"r");
  
$test fread($file,10);
  
fclose($file);
  print 
"We have read: [".htmlentities($test)."]";
?>

When you run the above script, the following should be displayed:

We have read: [<?xml vers]

Now, if that hangs as well, the first thing to look at is whether your server is having DNS problems; as this is the most common cause for a hang when opening Internet URLs. If your server cannot establish the IP address of "www.ziogiorgio.it" then it may hang whilst timing out trying to lookup the address.

One way to test if your server is having DNS problems is if you can login to your hosting account via Telnet or SSH. If you can, try something like:

ping www.example.com

...and that should tell you if it is a DNS problem...

Cheers,
David.

Submitted by cesare on Mon, 2006-07-24 13:19

Hello David,
the test scripts hangs and I get this:

Warning: fopen(): php_hostconnect: connect failed in /[etc.]/index4.php on line 3

Warning: fopen(http://www.ziogiorgio.it/rss_feed.xml): failed to open stream: Connection timed out in /[etc.]/index4.php on line 3

Warning: fread(): supplied argument is not a valid stream resource in /[etc.]/index4.php on line 4

Warning: fclose(): supplied argument is not a valid stream resource in /[etc.]/index4.php on line 5
We have read: []

If I try to ping the domain from inside the server I get this:
PING ziogiorgio.it (72.3.133.42) 56(84) bytes of data.
but then it hangs... and I have to ctrl-c to get access again to the ssh shell. Is it perhaps because I am behind a firewall?

Thank you for your assistance,
Cesare

Submitted by support on Mon, 2006-07-24 13:24

Hi Cesare,

Yes - it does look like the firewall is stopping your server from making out bound connections.

I can tell this from your PING command; because PING first resolves the IP address (which you can see); and then tries to send some packets. But ping is crashing just like your PHP script; so I think it is your firewall.

Therefore, you will need to contact whoever is responsible for your firewall (your network administrator or hosting company) and ask them to let your server make outbound HTTP connections (port 80). You should then be able to use fopen() in PHP with Internet URLs.

Cheers,
David.

Submitted by cesare on Mon, 2006-07-24 14:27

Thank you David,
it was a firewall/DNS problem. I have added an entry in the /etc/hosts file and now it works! :-)