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

2007-03-03 Thread Haydar Tuna
Hello,
 Richard Lynch is right. mysql_pconnect is a good connection method. 
In this method, we use only open connections. We don't open a new 
connection. If you use mysql_pconnect , you don't need mysql_close  because 
this is persistent connection.
 You can restart mysql with cron if your mysql server is down. 
Firstly, you can write a shell script to call from crontab file. In this 
shell script, you must call a php script that controls the connection. if 
your mysql connection is failed , the php script can set the your ENV 
variable (Envrimental Variables) true or false. In shell script , you can 
control that ENV variable. if ENV variable is false, your can start your 
mysql server:)


-- 
Haydar TUNA
Republic Of Turkey - Ministry of National Education
Education Technology Department Ankara / TURKEY
Web: http://www.haydartuna.net


Richard Lynch [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
 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



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

2007-03-01 Thread Brian Dunning
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.


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.


Thanks...  :)

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



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

2007-03-01 Thread Richard Lynch
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