Sunday, April 3, 2011

Why does fgets hang on a certain url on wamp, but is fine on mamp?

I have a script that reads RSS feeds using fopen & fgets.

When trying to the feed at: http://rss.fok.nl/feeds/nieuws my script hangs until the max_timeout of the PHP is reached.

The thing is:

  • it worked perfectly (on the same url) until today.
  • it still works on my development mac MAMP server.
  • it doesn't work on the production WAMP server (php 5.2.8)

I tried fread with no success.

any ideas?

From stackoverflow
  • Perhaps try to debug your connection using wireshark (Ethereal). This should give you the reason. Perhaps the webserver is blocking your requests because of the user-agent.

    Can you download the file manually on the Windows machine?

    Omer : manually it works fine
  • Well, it's more of a workaround than an answer, but I had to resort to it. I used the following to switch over to curl, using this function:

    function curl_get_file_contents($URL)
    {
        $c = curl_init();
        curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($c, CURLOPT_URL, $URL);
        $contents = curl_exec($c);
        curl_close($c);
    
        if ($contents) return $contents;
            else return FALSE;
    }
    

    I found it here: http://il.php.net/manual/en/function.file-get-contents.php

    btw, in case anyone wants to dig deeper, according to other reports of fgets hanging, it seems it has something to do with the 'feof' or lack thereof...

0 comments:

Post a Comment