I have minized my code to narrow down the problem. The line of codes excutes and works fine on my machine, my other machine, and a hosting account. It however refuses to work on my server running IIS and PHP. It simply prints out TESTING1 keeps loading for sometime and then - nothing happens. <?php echo "TESTING1"; flush(); $file = "http://news.google.com/news?sourceid=navclient&ie=UTF-8&rls=GGLG,GGLG:2005-22,GGLG:en&q=hosting&output=rss"; if (!($fp = fopen($file, "r"))) { die("could not open XML input"); } echo "TESTING2"; flush(); ?> Can anybody help with this?
Also, you can try file_get_contents as a replacement for fopen. It makes for a simpler code as you don't have to open and close a file connection. $file = file_get_contents("http://news.google.com/news?sourceid=navclient&ie=UTF-8&rls=GGLG,GGLG:2005-22,GGLG:en&q=hosting&output=rss"); PHP: This worked fine for me on my server.
Not to sound stupid or something, but could it simply be a security setting or your firewall blocking php-cgi.exe's outgoing connections? (The script you provided works fine on my local IIS/PHP server.) And I agree to jestep, use file_get_contents if you have the opportunity,.. it's much simpler
Thank you all for your replies. Couldn't check this earlier because my host took away access on the server as my credit card did not process. Back online now. pixel_perfect: I tried it with a local file and it worked fine after adjusting some privileges. jestep: tried it with file_get_contents gave the same thing. It hangs for sometime after displaying testing1 and then stops execution with even displaying the error message. B.V.E: thats the first thing I thought off and I disabled the firewall that comes with plesk, the antivirus, and the windows firewall to see if that was the issue as it did work on my local pc. No luck though still got the same problem. Any further help would be greatly appreciated. Thanks
is there an error log in the folder with the file ? does your host allow fopen wrappers to open urls ? I'm not sure exactly what you want to do with the xml when you get it : <?php $file = "http://news.google.com/news?sourceid=navclient&ie=UTF-8&rls=GGLG,GGLG:2005-22,GGLG:en&q=hosting&output=rss"; if (!($fp = fopen($file, "r"))) { die("could not open XML input"); } else { while(!feof($fp)) { $xml .= fgets($fp, 128); } } print($xml); ?> PHP: But it certainly works .....
krakjoe: no I couldnt file an error file. As far as the wrapper, I think it does, this is on my dedicated server so I should be able to allow anything. The xml will be formatted and printed out - nothing serious. nico_swd: it prints out a 1 - this is normal, right?
Yes, that's good. That means PHP is allowed to open and access external addresses. I once noticed that the ! can cause errors on some servers when used like you do. Try is this way instead. if (!$fp = fopen($file, "r")) { PHP: