Hi,
fsockopen and fgets is very slow compared
to file("http://...").
I want to download some pages from a website using PHP. I first thought of using 'file("http://...")'. Getting a page is rather fast (1-2 sec to load the page from a local web server that load the page from a remote website). But I realised the web site returns pages that depend on the browser.
Thus I turned to fsockopen and fgets. And now, I get the result I want, but the same page needs 15 seconds to do load !!!
here is the code:
<?
function getAsp($url)
{
if (strpos($url, "?")!=0)
$url = $url."&frame=true";
else
$url = $url."?frame=true";
$fp = fsockopen ("msdn.microsoft.com", 80, $errno, $errstr, 30);
if (!$fp) {
echo "$errstr ($errno)<br>\n";
} else {
$cmd =
"GET $url HTTP/1.0\r\n".
"Accept-Language: es\r\n".
"User-Agent: Mozilla/4.0 (compatible; MSIE 5.0; Windows 98; DigExt)\r\n".
"Connection: Keep-Alive".
"Accept: image/gif, image/jpeg, */*".
"Host: Host: msdn.microsoft.com\r\n\r\n";
fputs ($fp, $cmd);
while (!feof($fp)) {
fgets($fp,128);
}
fclose ($fp);
}
}
$chkUrl_path = "/library/en-us/cmctl198/html/vbobjtreeview.asp";
?>
<XMP>
<?
getAsp($chkUrl_path);
// $lines = file("http://msdn.microsoft.com".$chkUrl_path."?frame=true");
?>
</XMP>