自動重啟了_SwooleFor 監控檔案變化自動重啟 Swoole 服務
技術標籤:自動重啟了
SwooleFor
監控你的 Swoole 程式檔案變化並自動重啟伺服器 - 適用於開發
Monitor for any changes in your swoole application and automatically restart the server - perfect for development
SwooleFor 的定位就如同 PHP 版本的 nodemon, node-dev
該專案使用 mix-phar 開發
依賴擴充套件 (Depend extensions)
- ext-swoole >= v4.4
- ext-inotify
下載 (Download)
- https://github.com/mix-php/swoolefor
使用 (Usage)
執行指令碼命令:
php swoolefor.phar --exec="php app.php arg..."
如果 disable_functions
禁用了 proc_open
方法,按如下方法執行:
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
全部命令引數
php swoolefor.phar --help
-e, --exec
Swoole application or other script start command-d, --daemon
Run in the background--watch
Watch code file directory--delay
File change delay processing (seconds)--ext
Monitor only changes to these extensions--signal
Send this signal to the process
執行指令碼命令
--exec
內部可以是任何命令,必須為絕對路徑,必須為前臺執行的常駐程式 (否則會導致不斷fork程序)
php swoolefor.phar --exec="php app.php"
也可使用短引數
php swoolefor.phar -e "php app.php"
執行非 PHP 指令碼
- node
php swoolefor.phar --exec="node app.js"
- python
php swoolefor.phar --exec="python app.py"
在後臺執行
SwooleFor 本身可以在後臺執行,這樣可以脫離終端,增加 --daemon
即可
php swoolefor.phar --exec="node app.js" --daemon
也可使用短引數
php swoolefor.phar --exec="node app.js" -d
指定監控目錄
--watch
的預設值為 --exec
引數中指令碼的當前目錄,如果指令碼是在 bin
目錄中則會監控上一級的目錄。
// 會自動監控 /data 目錄
php swoolefor.phar --exec="php /data/bin/app.php"
指定監控其他目錄
php swoolefor.phar --exec="php app.php" --watch=/tmp
推遲執行重啟
當更新了很多檔案時,我們並不希望程式一直頻繁的重啟,所以我們需要設定一個延遲執行重啟的時間,只有在達到設定的時間才執行重啟操作。
--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
重啟時傳送的訊號
程式重啟時終止程序是通過給程序傳送訊號完成的,當我們需要指定訊號時
--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/