BEWARE! mysql_pconnect could harm your server.

kiat

Active Member
Oct 11, 2001
31
0
306
Hi,

I would like to share this experience with everyone who might fall in to the same situation like me. Last month my server will be crashed every couple days randomly. Few days ago, I just found that it was from I have too many mysql connections. Below is an output from top command that I got before the server go down. I have 402 process running and 170 process were mysql. After this for a few mintues, the server will go down with last CPU load average that I saw about 62.

16:41:56 up 5 days, 50 min, 0 users, load average: 30.52, 19.98, 9.79
402 processes: 395 sleeping, 2 running, 5 zombie, 0 stopped
CPU0 states: 0.1% user 2.1% system 0.0% nice 0.0% iowait 97.0% idle
CPU1 states: 2.0% user 0.1% system 0.0% nice 0.0% iowait 97.1% idle
Mem: 1029256k av, 1019056k used, 10200k free, 0k shrd, 32396k buff
506132k actv, 48604k in_d, 11064k in_c
Swap: 1020088k av, 474904k used, 545184k free 98560k cached

I found that a user were using mysql_pconnect, with this command the connection to mysql will not be closed when script end. This will using resources and accumulate to nearly maximum limit of the server and the server will go down. Only reboot at power switch will fix this when it crash.

Then I go to php.ini and turn
mysql.allow_persistent = Off
and restart apache. It's now look like the server operate very good. I got mysql process below 20 almost all the time. I hope that it will help someone who are in the same situation like me. :)