Too many phpfork processes cause the overall performance to decline.

Source: Internet
Author: User
1. my colleague ran a php crawl, which would lead to a very high sleep, which is about several thousand levels. mysql will go down. wrote crontab # crontab-e ** 1 *** shdetect_php.shdetech_php content #! Binbashhost_dir 'cdsh' proc _ namemysqlbug_time 'date-R' pid0proc _ num () {n

1. my colleague ran a php crawl, which would lead to a very high sleep, which is about several thousand levels. mysql will go down. crontab # crontab-e **/1 ***/sh/detect_php.sh detech_php #! /Bin/bashhost_dir = 'CD/Sh' proc _ name = mysqlbug_time = 'date-R' pid = 0proc_num () {n

1. My colleague ran a php crawl, which would lead to a very high sleep value, which is about several thousand levels. mysql would then be down.

A crontab is written.

# Crontab-e


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



Detech_php content

#!/bin/bashhost_dir=`cd /sh`proc_name="mysql"bug_time=`date -R`pid=0proc_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 $2}'`}proc_numnumber=$?if [ $number -eq 0 ]then./restart_php_mysql.shproc_idecho " Kill the php and new mysql pid is : ${pid} :  ${bug_time} " >> php_mysql.log 2>&1elseproc_idecho " The mysql is working , ${bug_time} " >> php_mysql.log 2>&1echo "it's ok!"fi

The script explains that this script is very simple. It is used to determine whether the mysql process is 0. If it is 0, kill php, restart mysql, and write a log.


Restart_php_mysql.sh content
#!/bin/shkillall -9 phpservice mysql restart

Pkill will cause the script to be terminated directly after killing the process. Therefore, pkill is not used here.


Improved

#!/bin/bashhost_dir=`cd /sh`log_dir="/var/log/php_mysql_log/"proc_name="mysql"bug_time=`date -R`pid=0now_time=`date +%F`log_file="${log_dir}${now_time}.log"log_detect(){if [ ! -d "$log_dir" ];thenmkdir "$log_dir"fiif [ ! -f "$log_file" ]thentouch "$log_file"fi}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 $2}'`}proc_numnumber=$?if [ $number -eq 0 ]then./restart_php.shproc_idlog_detectecho " Kill the php and new mysql pid is : ${pid} :  ${bug_time} " >> ${log_dir}${now_time}.log 2>&1elseproc_idlog_detectecho " The mysql is working ,${pid} : ${bug_time} " >> ${log_dir}${now_time}.log 2>&1echo "it's ok!"fi
The updated content is to create logs by time.

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.