windows 使用 xxfpm 解決 php-cgi 進程自動關閉

 

windows 下 php-cgi 進程處理必定數量的訪問後,就會自動關閉,因爲沒辦法直接讓 php-cgi 進程支持更多的訪問數量,因此只能啓動多個進程來知足需求。php

xxfpm 是一個可執行程序,它能同時啓動多個 php-cgi 進程,而且在任何一個進程關閉時,都會從新啓動一個新的進程,始終保持必定數量的進程,這樣,就無需手動建立,省去了不少麻煩。linux

xxfpm 須要 pthreadGC2.dll 的支持,若是沒有,會報錯。將 pthreadGC2.dll 放在 xxfpm 的 bin 目錄下,便可啓動 xxfpm。windows

xxfpm 詳細介紹

經測試,支持Win32和Linux-x86平臺。對於用php的人,有了這個東西來維護必定數量的進程,就能制服常常崩潰退出的php-cgi啦!!!測試

Usage: xxfpm path [-n number] [-i ip] [-p port]
Manage FastCGI processes.spa

-n, --number number of processes to keep
-i, --ip ip address to bind
-p, --port port to bind, default is 8000
-u, --user start processes using specified linux user
-g, --group start processes using specified linux group
-r, --root change root direcotry for the processes
-h, --help output usage information and exit
-v, --version output version information and exitorm

第一個寫得比較標準的終端應用程序,我是看了cygwin的裏的一些源代碼,而後學會了如何使用getopt,算是寫得比較標準的,可是代碼也不短。進程

使用例子:
xxfpm z:/php5/php-cgi.exe -n 5 -p 8080ip

有人問,如何給程序加入參數?這個不難,使用雙引號便可,路徑要用"/"而不用"\"。例如要指定php.ini的路徑,能夠用下面例子:
xxfpm "z:/php5/php-cgi.exe -c z:/php5/php.ini" -n 5 -i 127.0.0.1 -p 8080ci

 

如何維護進程:get

Windows上使用CreateProcess建立進程,使用WaitForSingleObject等待進程結束;Linux上使用fork和 execl建立進程,使用waitpid等待進程結束。Linux的版本多了在建立子進程的時候能夠設置進程限制,可以以受限用戶方式來運行。

當進程管理器被關閉的時候,它所建立的全部子進程也必須被關閉。Windows上使用JobObject這個東西來把子進程與管理器的進程產生關 聯,感謝iceboy提供的資料!Linux上經過捕捉關閉信號,而後給全部子進程發送SIGTERM來結束子進程。詳見源代碼!!!

相關文章
相關標籤/搜索