SwooleFor
監(jiān)控你的 Swoole 程序文件變化并自動重啟服務(wù)器 - 適用于開發(fā)
Monitor for any changes in your swoole application and automatically restart the server - perfect for development
SwooleFor 的定位就如同 PHP 版本的 nodemon, node-dev
該項目使用 mix-phar 開發(fā)
依賴擴展 (Depend extensions)
下載 (Download)
使用 (Usage)
執(zhí)行腳本命令:
php swoolefor.phar --exec="php app.php arg..."
如果 disable_functions 禁用了 proc_open 方法,按如下方法執(zhí)行:
php -d disable_functions='' swoolefor.phar --exec="php app.php arg..."
啟動成功:
_____ __ ______
/ ___/ ______ ____ / /__ / ____/___ _____
\__ \ | /| / / __ \/ __ \/ / _ \/ /_ / __ \/ ___/
___/ / |/ |/ / /_/ / /_/ / / __/ __/ / /_/ / /
/____/|__/|__/\____/\____/_/\___/_/ \____/_/ Version: 1.1.1, Swoole: 4.4.0
[info] 2019-08-14 11:51:05.937 <920> [message] executor start, exec: [php /data/bin/mix-httpd start]
[info] 2019-08-14 11:51:05.938 <920> [message] fork sub process, pid: 921
[info] 2019-08-14 11:51:05.939 <920> [message] monitor start
[info] 2019-08-14 11:51:05.939 <920> [message] watch: /data
[info] 2019-08-14 11:51:05.939 <920> [message] delay: 3s
[info] 2019-08-14 11:51:05.939 <920> [message] ext: .php,.json
全部命令參數(shù)
php swoolefor.phar --help
-
-e, --execSwoole application or other script start command -
-d, --daemonRun in the background -
--watchWatch code file directory -
--delayFile change delay processing (seconds) -
--extMonitor only changes to these extensions -
--signalSend this signal to the process
執(zhí)行腳本命令
--exec 內(nèi)部可以是任何命令,必須為絕對路徑,必須為前臺執(zhí)行的常駐程序 (否則會導致不斷fork進程)
php swoolefor.phar --exec="php app.php"
也可使用短參數(shù)
php swoolefor.phar -e "php app.php"
執(zhí)行非 PHP 腳本
- node
php swoolefor.phar --exec="node app.js"
- python
php swoolefor.phar --exec="python app.py"
在后臺執(zhí)行
SwooleFor 本身可以在后臺執(zhí)行,這樣可以脫離終端,增加 --daemon 即可
php swoolefor.phar --exec="node app.js" --daemon
也可使用短參數(shù)
php swoolefor.phar --exec="node app.js" -d
指定監(jiān)控目錄
--watch 的默認值為 --exec 參數(shù)中腳本的當前目錄,如果腳本是在 bin 目錄中則會監(jiān)控上一級的目錄。
// 會自動監(jiān)控 /data 目錄
php swoolefor.phar --exec="php /data/bin/app.php"
指定監(jiān)控其他目錄
php swoolefor.phar --exec="php app.php" --watch=/tmp
推遲執(zhí)行重啟
當更新了很多文件時,我們并不希望程序一直頻繁的重啟,所以我們需要設(shè)置一個延遲執(zhí)行重啟的時間,只有在達到設(shè)置的時間才執(zhí)行重啟操作。
--delay 默認為 3s
php swoolefor.phar --exec="php app.php" --delay=5
指定觀察的擴展名
--ext 默認為 php,json,當需要觀察其他擴展名時可配置
php swoolefor.phar --exec="php app.php" --ext=php,json,ini
重啟時發(fā)送的信號
程序重啟時終止進程是通過給進程發(fā)送信號完成的,當我們需要指定信號時
--signal 默認為 15
php swoolefor.phar --exec="php app.php" --signal=1
常用的信號表
| 信號 | 值 |
|---|---|
| SIGTERM | 15 |
| SIGKILL | 9 |
| SIGHUP | 1 |
| ... | ... |
支持流行的 Swoole 框架
- MixPHP:
php swoolefor.phar -e "php /data/bin/mix-httpd start -c /data/applications/http/config/httpd.php"
- Swoft:
php swoolefor.phar -e "php /data/bin/swoft http:start"
- EasySwoole:
php swoolefor.phar -e "php /data/bin/easyswoole start"
- laravel-s
php swoolefor.phar -e "php /data/bin/laravels start"
License
Apache License Version 2.0, http://www.apache.org/licenses/