代码见真章,请勿直接用,按注释修改。
#NoTrayIcon
AutoItSetOption("MustDeclareVars", 1);限定变量必须先定义后使用,防止出错
;定义全局常量
Global Const $phpDir = "D:\Webserver\PHP53";PHP 路径
Global Const $phpFile = "php.exe";PHP 程序名
Global Const $phpExe = $phpDir & "\" & $phpFile;PHP 完整路径
Global Const $phpCgiFile = "php-cgi.exe";PHP-CGI 程序名
Global Const $phpCgiExe = $phpDir & "\" & $phpCgiFile;PHP-CGI 完整路径
Global Const $phpIniFile = "php.ini";PHP.INI 名
Global Const $phpIni = $phpDir & "\" & $phpIniFile;PHP.INI 完整路径
__onStart();运行前执行
OnAutoItExitRegister("__onExit");注册回调(退出后执行)
__main();执行主函数
Exit;退出
#comments-start
启动时运行函数
#comments-end
Func __onStart()
EndFunc ;==>__onStart
#comments-start
主函数
#comments-end
Func __main()
If ($CmdLine[0] >= 1) Then
__cmdMain()
Exit
EndIf
EndFunc ;==>__main
#comments-start
命令行主函数
#comments-end
Func __cmdMain()
While 1
If (__checkPhpCgiProcess() < $CmdLine[1]) Then
__runPhpCgi($CmdLine[1] - __checkPhpCgiProcess())
EndIf
Sleep(10000)
WEnd
EndFunc ;==>__cmdMain
#comments-start
退出时运行函数
#comments-end
Func __onExit()
EndFunc ;==>__onExit
#comments-start
检查 PHP-CGI 是否在运行
@return boolean 运行返回 true,否则返回 false
#comments-end
Func __checkPhpCgiState()
Return ProcessExists($phpCgiFile)
EndFunc ;==>__checkPhpCgiState
#comments-start
检查 PHP-CGI 进程数
@return int 返回目前 PHP-CGI 进程数
#comments-end
Func __checkPhpCgiProcess()
Local $phpCgiProcessArray = ProcessList($phpCgiFile)
Return IsArray($phpCgiProcessArray) ? $phpCgiProcessArray[0][0] : 0;
EndFunc ;==>__checkPhpCgiProcess
#comments-start
运行 PHP-CGI
@param int $start 运行几个 PHP-CGI
#comments-end
Func __runPhpCgi($start = 3)
Local $i = 1
For $i = 1 To $start Step 1
Run($phpCgiExe & " -b 127.0.0.1:9000", $phpDir, @SW_HIDE)
Next
EndFunc ;==>__runPhpCgi
#comments-start
结束 PHP-CGI
#comments-end
Func __stopPhpCgi()
While __checkPhpCgiState()
__closePhpCgiProcess()
WEnd
EndFunc ;==>__stopPhpCgi
#comments-start
结束 PHP-CGI 进程
#comments-end
Func __closePhpCgiProcess()
ProcessClose($phpCgiFile)
EndFunc ;==>__closePhpCgiProcess