Re: [X-POST] PHP script to make sure MySQL is up?
| From: | Richard Lynch | Date: | Thu, 01 Mar 2007 22:19:46 +0000 |
| Subject: | Re: [X-POST] PHP script to make sure MySQL is up? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-249678@lists.php.net to get a copy of this message | ||
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?