>From time to time I seem to see error messages in my database.err log file 
for MySQL.

020130 11:19:10  Aborted connection 40437 to db: 'xyz' user: 'abc' host: 
`localhost' (Got an error reading communication packets)

I've been reading about the Morning Bug and here's what I extracted about it:

The error was caused by Apache::DBI returning a handle of the invalid 
connection (the server closed it because of a timeout), and the script was 
dying on that error.  The ping() method was introduced to solve this problem.

Here's an example of what is essentially a database ping:

unless ($self->{dbh} and $self->{dbh}->do("SELECT 1")) {
  $self->{dbh} = DBI->connect("dbi:mysql:$self->{database}:$self->{server}",
                                $self->{user},$self->{password});
}

Here's an example of Apache::DBI ping:

sub Apache::DBI::db::ping {
  my $dbh = shift;
  return $dbh->do(`select 1`);
}

Another solution was found - to increase the timeout parameter when starting 
the database server, the default is set to 8 hours.

172800 seconds is equal to 48 hours. This change solves the problem, but the 
ping() method works properly in DBD::mysql as well.

Currently, I've added the following code to my scripts:

$dbh = DBI->connect("DBI:mysql:$database_name:$host:3306", "User", "Password",
                    {RaiseError => 1, PrintError => 1});

if (! $dbh) {
  $dbh = DBI->connect
("DBI:mysql:$database_name:$host:3306", "User", "Password",
                    {RaisError => 1, PrintError => 1});
}

So, I create a database handle but if the database handle doesn't exist on 
the first try, I try to create it again.

I'd like to know, which is best method for handling this situation?

I've also created a wrapper for my DBI usage and I trap and present error 
messages of my own in my log.  However, sometimes I may have an entry 
that says "No database connection" and I'd expect to see an "Aborted..." 
message in my database.err log file but I don't.  Can you shed some light 
on this?

Lastly, I have a CGI-BIN script that produces dynamic webpages and people 
sometimes click stop, then start (especially when doing searches) 
multiple times.  So, as the httpd processes eventually die off I'll still 
have some MySQL threads lying around, how do I run down those useless 
threads and keep by max_connections down?

Thanks in advance, cheers.

Ozette

--
Email:  [EMAIL PROTECTED]

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