Henry Grech-Cini wrote:

Hi All,

I am trying to check if a website is up (reachable) and I have used the
standard code below:

Unfortunately this works for most sites but Microsoft doesn't work most of
the time even thought the site is definiately up! (Occassionally it does say
it is reachable but only occassionaly and thats whats even more confusing).

Suggestions?

Try inserting die('breakpoint'); in each of your if() blocks. When you stop seeing it, there's your error :)



Henry


I tried URL's as follows:

http://www.microsoft.com/
http://www.microsoft.com



   function url_reachable( $link )
   {
       $url_parts = @parse_url( $link );

if ( $url_parts["scheme"]!="http" ) return ( false );

if ( empty( $url_parts["host"] ) ) return( false );

       if ( !empty( $url_parts["path"] ) )
       {
           $documentpath = $url_parts["path"];
       }
       else
       {
           $documentpath = "/";
       }

       if ( !empty( $url_parts["query"] ) )
       {
           $documentpath .= "?" . $url_parts["query"];
       }

       $host = $url_parts["host"];
       $port = $url_parts["port"];
       // Now (HTTP-)GET $documentpath at $host";

       if (empty( $port ) ) $port = "80";
       $socket = @fsockopen( $host, $port, $errno, $errstr, 30 );
       if (!$socket)
       {
           return(false);
       }
       else
       {
           fwrite ($socket, "HEAD ".$documentpath." HTTP/1.0\r\nHost:
$host\r\n\r\n");
           $http_response = fgets( $socket, 22 );

if ( ereg("200 OK", $http_response, $regs ) )

Well there are plenty of other HTTP responses you could be getting instead of just 200. Perhaps you are getting redirections or other messages?


           {
               return(true);
               fclose( $socket );
           } else
           {
//                echo "HTTP-Response: $http_response<br>";
               return(false);
           }
       }
   }

-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to