php fork太多进程导致整体性能下降,mysql down掉的解决._PHP教程

WBOY
Freigeben: 2016-07-14 10:10:10
Original
1006 Leute haben es durchsucht

1.同事跑了一个php的抓取, 这个会导致非常高的sleep值,大概到好几千的水平.进而mysql会down掉.

写了个crontab

#crontab -e

 


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

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

 

 

 

detech_php 的内容

 

[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 $2}'` 

 
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 $2}'`
}

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

脚本解释,这个脚本非常简单的. 就是判断mysql进程是否为0, 如果为0,那么就去杀掉php,然后重启mysql.并且写入一个日志.


restart_php_mysql.sh 的内容

[php]
#!/bin/sh 
killall -9 php 
service mysql restart 

#!/bin/sh
killall -9 php
service mysql restart

pkill会导致脚本在杀完进程后直接terminated. 所以这里不使用pkill. 

 

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/477528.htmlTechArticle1.同事跑了一个php的抓取, 这个会导致非常高的sleep值,大概到好几千的水平.进而mysql会down掉. 写了个crontab #crontab -e [php] * */1 * * * /sh/detect_p...
Verwandte Etiketten:
Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!