WINDOWS PHP-CGI频繁掉线,PYTHON进程监控来曲线救国

执行环境:python33

 

 

import threading
import time
import os
import subprocess

php_cgi_name = 'php-cgi.exe';
php_cgi_path = 'D:/wamp/php/5.5.10/php-cgi.exe';
php_cgi_arg = "-b127.0.0.1:9000 -cD:/wamp/php/5.5.10/php.ini";

def get_process_count(imagename):
    p = os.popen('tasklist /FI "IMAGENAME eq %s"' % imagename)
    return p.read().count(imagename)
 
def timer_start():
    t = threading.Timer(1,watch_func)
    t.start()

def watch_func():
    if get_process_count(php_cgi_name) == 0 :
        print("{0} 正在重启:{1},进程:{2}".format(time.strftime("%Y-%m-%d %H:%M:%S"), php_cgi_name, subprocess.Popen([php_cgi_path, php_cgi_arg])))
    timer_start()

if __name__ == "__main__":
    timer_start()
    while True:
        time.sleep(1)

 

posted on 2014-04-24 17:22  mtima  阅读(479)  评论(0编辑  收藏  举报

导航