Re: how do i check if a server is online ?

From: Date: Tue, 27 Feb 2001 13:32:25 +0000
Subject: Re: how do i check if a server is online ?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-41836@lists.php.net to get a copy of this message
mysql_connect does not have a timeout option :( I wonder if your timeout is not because of mysql_connect but more a dns problem, try putting the IP in, see if it times out at a more reasonable speed. if not try fsockopen http://php.net/manual/en/function.fsockopen.php open the port, if no errors, close the port and continue, if there are errors then you know the server is down. fsockopen allows for a timeout option, set it to 2 sec or something, should be ok. <?php if ( !($fp = fsockopen ('mysql.server.com', 3306, $errno, $errstr, 2)) ) { echo " There has been an error : $errstr ($error) <br> "; } else mysql_connect('mysql.server.com', 'mysql_user', 'mysql_passwd'); ?> is this server prone to alot of ups and downs ? might want to stay away from mysql_pconnect(). -- Chris Lee Mediawaveonline.com ph. 250.377.1095 ph. 250.376.2690 fx. 250.554.1120 lee@mediawaveonline.com ""Markus H. Maussner"" <markus@e-commerceit.de> wrote in message news:Pine.LNX.4.21.0102271601480.1892-100000@pcmaussner.e-commerceit.de... > hi.. > > 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 ? > > markus > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net >

« previous php.general (#41836) next »