Google Answers Logo
View Question
 
Q: MySQL Database ( Answered,   1 Comment )
Question  
Subject: MySQL Database
Category: Computers > Programming
Asked by: thierry_bellevue-ga
List Price: $10.00
Posted: 30 Dec 2005 03:55 PST
Expires: 29 Jan 2006 03:55 PST
Question ID: 611236
It's about MySQL Database. I just want to know how can I prevent from
getting many "Sleep" command processes which can be much longer than
300 (Time). Sometime I can have much than 10 processes with "Sleep"
command longer than 500 (Time).
Answer  
Subject: Re: MySQL Database
Answered By: hedgie-ga on 27 Jan 2006 11:47 PST
 
Your typical dialog should

open,
work with,
and close

connections. If you do not close them, they persist.
example:

----------------------------------\\
<?php
//Open connection
    $db2 = mysql_connect($host, $dabu, $dabap);
    mysql_select_db($dab,$db2);

process your querries

AND 

// Close MySQL Connection
mysql_close($db2);
?>
--------------------------------//

detailed example:

http://dev.mysql.com/doc/refman/5.0/en/dao--rs-addnew.html

manual
http://cz2.php.net/function.mysql-pconnect
http://helpguide.inmotionhosting.com/php_faq/function.mysql-close.html
Comments  
Subject: Re: MySQL Database
From: liorcohega-ga on 01 Jan 2006 03:57 PST
 
the "sleep" status processes you see in your mysql, is a connection
made to your database from (my guess) a web server and probably an
apache web server.

note that the amont of "idle connections" (or sleep commands as you
call them) cannot crash the mysql or overload it, the only problem
that might happen is reaching the maximum opened connections you allow
to your mysql.

by default php will use persistent connections to you mysql which
means, that it will first try to use an existing connection for a new
database access, if not it will open a new one, since apache use
different threads it will allways open a new connection while the
other one is idle and it cannot use that one.

you can minimize it by not allowing persistent connections in your php.ini file

[MySQL]
; Allow or prevent persistent links.
mysql.allow_persistent=Off

and restart you web server daemon.

this way the conection "SHOULD" be closed after the script has finished running.

hope it helps
lior

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy