Can't figure this out - need help

Discussion in 'PHP' started by fuser, Dec 21, 2006.

  1. #1
    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?:confused:
     
    fuser, Dec 21, 2006 IP
  2. pixel_perfect

    pixel_perfect Banned

    Messages:
    238
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    try with local file first. once it works then try remote url.
     
    pixel_perfect, Dec 21, 2006 IP
  3. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #3
    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.
     
    jestep, Dec 21, 2006 IP
  4. B.V.E.

    B.V.E. Peon

    Messages:
    106
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #4
    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 :)
     
    B.V.E., Dec 21, 2006 IP
  5. fuser

    fuser Peon

    Messages:
    541
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #5
    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
     
    fuser, Dec 28, 2006 IP
  6. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #6
    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, Dec 28, 2006 IP
  7. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #7
    What does this output for you?

    
    
    echo ini_get('allow_url_fopen');
    
    PHP:
     
    nico_swd, Dec 28, 2006 IP
  8. fuser

    fuser Peon

    Messages:
    541
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #8
    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?
     
    fuser, Dec 28, 2006 IP
  9. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #9
    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:
     
    nico_swd, Dec 29, 2006 IP