Re: [X-POST] PHP script to make sure MySQL is up?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, March 1, 2007 1:37 pm, Brian Dunning wrote:
> I host at Rackspace, and one thing that their monitoring service does
> NOT catch is a problem when too many connections hit MySQL, and for
> some reason it remains hung up until the service is manually
> restarted. In the meantime, this is happening to us once or twice a
> month. It gets hammered with a huge number of brief connections from
> other Apache servers.
>
> Slow queries and mysql_close() are NOT the problem. It's just too
> many connections, even though they're super fast.

Are you using mysql_pconnect?

Because that is essentially going to lock one MySQL connection to each
Apache child, and if you have a bigger httpd.conf MAX_CHILDREN than
you have /etc/my.cnf number of connections, then, by definition, you
are going to have problems all the time, because you have more "users"
than "connections" available.

Note also that each username/password gets its own persistent
connection, so if you have two DB roles in your application, then you
have just doubled the number of connections needed.

In something like a shared hosting environment, pconnect is probably a
death knell, since every little user will be tying up a connection for
their app.  There are, of course, ways around this, such as dedicated
apache pools per client, or super-short connection time-out on the
persitence or...  But most shared hosts aren't going to go to this
length.

> Is there such a thing as a PHP script that I can put on a cron job to
> run every minute and make a test query, and upon failure, restart the
> service and maybe send an email to Rackspace support? I don't know
> how you'd check that the query was refused due to too many
> connections, and I also don't know how PHP would restart the MySQL
> service.

I think mysql_connect should be providing you with a nice error
message if this does happen.

Are you checking mysql_error right after your mysql_connect call?

And you almost-for-sure don't want any random old php script capable
of bouncing the MySQL server...
[shudder]

-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux