Re: Using PHP to test if server is online

From: Date: Tue, 03 Jul 2001 11:36:18 +0000
Subject: Re: Using PHP to test if server is online
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-55969@lists.php.net to get a copy of this message
>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: GEBiernat@real.com Germany URL : http://de.real.com ______________________________________________________________

« previous php.general (#55969) next »