PHP fork too many processes lead to overall performance degradation, MySQL down resolution. _php Tutorial

Source: Internet
Author: User
Tags pkill
1. Colleagues ran a PHP crawl, this will lead to very high sleep value, about thousands of of the level. Then MySQL will be down.

Wrote a crontab.

#crontab-E


[PHP]
* */1 * * */sh/detect_php.sh

* */1 * * */sh/detect_php.sh

Detech_php's Content

[PHP]
#!/bin/bash

Host_dir= ' cd/sh '
Proc_name= "MySQL"
Bug_time= ' Date-r '
Pid=0

Proc_num ()
{
Num= ' Ps-ef | grep $proc _name | Grep-v grep | Wc-l '
return $num
}

PROC_ID ()
{
Pid= ' Ps-ef | grep $proc _name | Grep-v grep | awk ' {print $} '
}

Proc_num
Number=$?
If [$number-eq 0]
Then
./restart_php_mysql.sh
proc_id
echo "Kill the PHP and new MySQL pid is: ${pid}: ${bug_time}" >> Php_mysql.log 2>&1
Else
proc_id
echo "The MySQL is working, ${bug_time}" >> Php_mysql.log 2>&1
echo "It ' s ok!"
Fi

#!/bin/bash

Host_dir= ' cd/sh '
Proc_name= "MySQL"
Bug_time= ' Date-r '
Pid=0

Proc_num ()
{
Num= ' Ps-ef | grep $proc _name | Grep-v grep | Wc-l '
return $num
}

PROC_ID ()
{
Pid= ' Ps-ef | grep $proc _name | Grep-v grep | awk ' {print $} '
}

Proc_num
Number=$?
If [$number-eq 0]
Then
./restart_php_mysql.sh
proc_id
echo "Kill the PHP and new MySQL pid is: ${pid}: ${bug_time}" >> Php_mysql.log 2>&1
Else
proc_id
echo "The MySQL is working, ${bug_time}" >> Php_mysql.log 2>&1
echo "It ' s ok!"
Fi

The script explains that this script is very simple. is to determine whether the MySQL process is 0, if it is 0, then go to kill PHP, and then restart MySQL. and write a log.


Restart_php_mysql.sh's Content

[PHP]
#!/bin/sh
killall-9 PHP
Service MySQL Restart

#!/bin/sh
killall-9 PHP
Service MySQL Restart

Pkill causes the script to terminated directly after the process has finished killing. So we don't use pkill here.

http://www.bkjia.com/PHPjc/477528.html www.bkjia.com true http://www.bkjia.com/PHPjc/477528.html techarticle 1. Colleagues ran a PHP crawl, this will result in a very high sleep value, about thousands of of the level. Then MySQL will be down. wrote a crontab #crontab-e [PHP] * */1 * * * */sh/detect_p ...

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.