Hi all
This is a weird one. I would appreciate some opinions.
I have a bit of code I have been using for years to scrape bits of data from various websites. It has always worked fine.
This is the code. As you can see, there is nothing strange.
$openURL = fsockopen($host,80,$errNo,$errStr,20);
if (!$openURL) {
echo "$host: $errStr ($errNo)\n";
} else {
$header .= "GET ".$url." HTTP/1.0\r\n";
$header .= "HOST: ".$host."\r\n";
$header .= "Referer: ".$host."\r\n";
$header .= "User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:11.0) Gecko/20100101 Firefox/11.0\r\n";
$header .= "Cookie: ".$cookie."\r\n";
$header .= "Connection: close\r\n\r\n";
if (fputs($openURL,$header))
while(!feof($openURL))
$content .= fgets($openURL,128);
fclose($openURL);
}
The problem is this:
For one particular website I am scraping, the fputs is successful, but the while loop never happens. I have tried calling fgets without the while loop and FALSE is returned.
This code used to work at this website.
I am able to access the website from my browser. I have used Live HTTP headers in Firefox and the website isn't doing anything strange.
Can any of you think of how I can figure out what exactly is causing this error? For example, is there some error code I can view which will tell me why fgets is returning FALSE?
Any advice appreciated.
Thanks
Steve