>I am writing a PHP script to test if the server on which it is running is
>currently connected to the Internet. If so, the main page will display a
>notice saying "We are now online", else it will say "Not connected"
>
>Any ideas on how to do this with PHP? I'm guessing it would involve some
>kind of socket connection...

Yep. Simply open a socket connection as described in:
http://www.php.net/manual/en/function.fsockopen.php

I once wrote an RTSP (Real Time Streaming Protocol) link checker using that, works 
flawlessly.

$sockethandle = fsockopen($host, $port);

if ($sockethandle) {
        # Lets query document root
        $query = "GET / HTTP/1.0\n\n";
        # Send the query
        fputs($sockethandle, $query);
        # Receive first line of response
        $response = trim(fgets($sockethandle, 1024));
}

Remember, using fsockopen is more or less like telnet-ing to the server, standard HTTP 
port is 80. But querying a web server can easier be done by doing a 
file($url_of_server).

If it's just to tell if a server is online, nearly any method will do, including DNS 
lookups or a simple system call with ping... :-)


mit freundlichen Gruessen / yours sincerely


Gunther E. Biernat
Web Application Engineer
______________________________________________________________

RealNetworks GmbH                   Tel.: +49-40-415204-24
Weidestraße 128                     Fax.: +49-40-415204-11
22083 Hamburg                       Mail: [EMAIL PROTECTED]
Germany                             URL : http://de.real.com
______________________________________________________________



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to