----- Original Message -----
From: "Melvyn Sopacua" <[EMAIL PROTECTED]>
To: "Gelu Gogancea" <[EMAIL PROTECTED]>
Cc: "MySQL General" <[EMAIL PROTECTED]>
Sent: Sunday, June 02, 2002 10:27 PM
Subject: Re: mysql_ping()


> >So... you don't need mysql_ping ... unless if want to check periodical if
> >the server is "alive".
>
> Yes and no. I do want that, but afterwards I want to connect.


It still does not look to me like you really want to ping the server. What
you seem to want is to check whether the server is alive; and if not,
reconnect; right? In Perl I handled it by going it the simple route: instead
of pinging the server, I check whether my DBI handle is still alive. Like
this,

sub connect_mysql {
    $dbh = DBI -> connect ( ... );
}

And I start every relevant sub with this,

$dbh ||= connect_mysql ();

The "or is" operator is a very fast early-out mechanism, that simply checks
whether $dbh is still "alive;" and if it no longer is, reconnects. I use
that for my MySQL based news server. Works like a charm. I can go into
phpMyAdmin, kill the process, and find the news server reconnect again as if
nothing happened.

I do not believe PHP has such a "or is" operator; but a simple "if ($dbh) {"
construct would suffice too.

- Mark

        System Administrator Asarian-host.org

---
"If you were supposed to understand it,
we wouldn't call it code." - FedEx


---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to