发信人: xfgavin (跨越时空的神秘), 信区: Network
标 题: Windows下php-cgi的监控脚本
发信站: BBS 木铎金声站 (Sat Sep 5 10:45:24 2009), 站内
如果在windows下用phpfastcgi的话,经常会碰到php-cgi.exe退出的问题,我的解决方法是
多放几个phpfastcgi服务进行负载均衡和failover,并用如下脚本隔两分钟监控一下
'''''''''''''''''''''''''''''''''''''''''''''''
'An WMI Instance of Win32 Service Controller '
'xfgavin@gmail.com bbs.mdjs.org
'''''''''''''''''''''''''''''''''''''''''''''''
Dim isPHPFastCGIalive, WMI, Process, Processes, WshShell, isPHPFastCGI9000alive, isPHPFastCGI9001alive, isPHPFastCGI9002alive, isPHPFastCGI9003alive,
isPHPFastCGI9004alive, ServiceCount, Services, Service
Set WMI = GetObject("winmgmts:\\.\root\cimv2")
Set Processes = WMI.ExecQuery("select * from win32_process where name='php-cgi.exe'")
isPHPFastCGI9000alive = False
isPHPFastCGI9001alive = False
isPHPFastCGI9002alive = False
isPHPFastCGI9003alive = False
isPHPFastCGI9004alive = False
ServiceCount = 0
For Each Process In Processes
Select Case Right(Process.CommandLine, 4)
Case 9000
isPHPFastCGI9000alive = True
Case 9001
isPHPFastCGI9001alive = True
Case 9002
isPHPFastCGI9002alive = True
Case 9003
isPHPFastCGI9003alive = True
Case 9004
isPHPFastCGI9004alive = True
End Select
ServiceCount = ServiceCount + 1
Next
If ServiceCount <> 5 Then
If Not isPHPFastCGI9000alive Then
Set Services = WMI.ExecQuery("select * from win32_service where name='phpfastcgi9000'")
For Each Service In Services
Service.StopService
Service.StartService
Next
Set Services = Nothing
End If
If Not isPHPFastCGI9001alive Then
Set Services = WMI.ExecQuery("select * from win32_service where name='phpfastcgi9001'")
For Each Service In Services
Service.StopService
Service.StartS
isPHPFastCGI9004alive = True
End Select
If Not isPHPFastCGI9002alive Then
Set Services = WMI.ExecQuery("select * from win32_service where name='phpfastcgi9002'")
For Each Service In Services
Service.StopService
Service.StartService
Next
Set Services = Nothing
End If
If Not isPHPFastCGI9003alive Then
Set Services = WMI.ExecQuery("select * from win32_service where name='phpfastcgi9003'")
For Each Service In Services
Service.StopService
Service.StartService
Next
Set Services = Nothing
End If
If Not isPHPFastCGI9004alive Then
Set Services = WMI.ExecQuery("select * from win32_service where name='phpfastcgi9004'")
For Each Service In Services
Service.StopService
Service.StartService
Next
Set Services = Nothing
End If
End If
--
FROM 59.109.6.*