RE: [PHP] how do i check if a server is online ?
| From: | Marc Swanson | Date: | Tue, 27 Feb 2001 15:29:35 +0000 |
| Subject: | RE: [PHP] how do i check if a server is online ? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-41835@lists.php.net to get a copy of this message | ||
> i have the problem that i need to connect to a database on a server wich
> is quiet often offline.
>
> how can i connect to this database (mysql) and can check if the server is
> online.
> like.. if server is online -> fine we work as normaly
> if server is NOT online -> print out message and say "server offline try
> later"....
>
> i tried something like mysql_connect and then die ...
> but it takes approx 5 mins.. till i get the message..
> do i have to set the timeout lower? and if yes.. how do i do that ?
This should do what you want:
system("ping -c 1 www.someurl.com", $retval);
if($retval == 0) {
#server is alive
}
else {
#server is down
}
HTH
-Marc-
#/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/#
#Marc Swanson | \|||/ #
#MSwanson Consulting | /o o\ #
#Phone: (603)868-1721 |-ooo----O----ooo-#
#Fax: (603)868-1730 | Solutions in: #
#marcswanson@mediaone.net | 'PHP 'Perl #
# | 'SQL 'C++ #
# | 'HTML 'Sh/Csh#
# http://www.mswanson.com | 'Javascript #
#/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/#