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

 [EMAIL PROTECTED]



""Markus H. Maussner"" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> 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: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]
>



-- 
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