I have created a page that is supposed to check a given link and report if it is good or not. The results I have been getting have not been very predictable. All URLs I have tested I know are active, but some will still fail. At this point, I can not find any common reason as to why they are failing.
As an example, http://www.google.com/ will fail every time, but http://www.apple.com/ will pass every time.
Is fsockopen limited to the DNS configuration of the server? If so, could the problem I am seeing be just a DNS lookup issue with my web host?
Here is the code I am working with. Can you see anything that might be causing my problems. Or am I just way off in my attempt to write this code?
Thanks in advance.
Nibbi
<?php
$ok = "HTTP/1.1 200 OK";
$purl=parse_url("$url");
$site = "$purl[host]";
$rip = "$purl[path] . $purl[query]";
$file = fsockopen($site, 80, $errno, $errstr, 300);
if($file){
fputs($file, "HEAD " . $rip . " HTTP/1.0\r\n\r\n");
while(!feof($file))
{
$data[] = fgets($file, 1000);
}
fclose($file);
}
reset($data);
$data[0]= chop($data[0]);
if($data[0] === $ok){
echo "<br><br>$data[0] - yes!!";
}else{
echo "<br><br>$data[0] - NO!";
}
echo "<br>site:$site<br>
purl[host]: $purl[host]<br>
purl[path]: $purl[path]<br>
purl[query]: $purl[query]<br>
total: $site$purl[path]$purl[query]";
?>