Skip to content
This repository has been archived by the owner on Jul 28, 2022. It is now read-only.

监控你的 Swoole 程序文件变化并自动重启服务器 - 适用于开发 / Monitor for any changes in your swoole application and automatically restart the server - perfect for development

License

mix-php/swoolefor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

96 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

注意:由于不断出现各种兼容性问题,本项目已经停止维护。

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 Skeleton 开发

依赖扩展 (Depend extensions)

下载 (Download)

使用 (Usage)

执行脚本命令,--exec 内部的文件路径必须为绝对路径

php swoolefor.phar --exec="/usr/bin/php /data/app.php arg..."

当系统环境对 inotify 扩展无法支持时,如:虚拟机挂载目录、MacOS 系统,可通过切换为文件扫描的方式捕获代码更新:

php swoolefor.phar --exec="/usr/bin/php /data/app.php arg..." --no-inotify

启动范例:

$ php swoolefor.phar --exec="/usr/bin/php /data/bin/mix.php web"
   _____                     __     ______          
  / ___/      ______  ____  / /__  / ____/___  _____
  \__ \ | /| / / __ \/ __ \/ / _ \/ /_  / __ \/ ___/
 ___/ / |/ |/ / /_/ / /_/ / /  __/ __/ / /_/ / /    
/____/|__/|__/\____/\____/_/\___/_/    \____/_/  Version: 1.1.3, Swoole: 4.4.5, Use: inotify

[info] 2019-08-14 11:51:05.937 <920> [message] executor start, exec: [/usr/bin/php /data/bin/mix.php web]
[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
  • --no-inotify Do not use the inotify extension
  • --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="/usr/bin/php /data/app.php"

也可使用短参数

php swoolefor.phar -e "/usr/bin/php /data/app.php"

执行非 PHP 脚本

  • node
php swoolefor.phar --exec="/usr/bin/node /data/app.js"
  • python
php swoolefor.phar --exec="/usr/bin/python /data/app.py"

在后台执行

SwooleFor 本身可以在后台执行,这样可以脱离终端,增加 --daemon 即可。

php swoolefor.phar --exec="/usr/bin/php /data/app.php" --daemon

也可使用短参数

php swoolefor.phar --exec="/usr/bin/php /data/app.php" -d

不使用 inotify

当系统环境对 inotify 扩展无法支持时,可通过切换为文件扫描的方式捕获代码更新。

php swoolefor.phar --exec="/usr/bin/php /data/app.php" --no-inotify

指定监控目录

--watch 的默认值为 --exec 参数中脚本的当前目录,如果脚本是在 bin 目录中则会监控上一级的目录。

// 会自动监控 /data 目录
php swoolefor.phar --exec="/usr/bin/php /data/bin/app.php"

指定监控其他目录

php swoolefor.phar --exec="/usr/bin/php /data/app.php" --watch=/tmp

推迟执行重启

当更新了很多文件时,我们并不希望程序一直频繁的重启,所以我们需要设置一个延迟执行重启的时间,只有在达到设置的时间才执行重启操作。

--delay 默认为 3s

php swoolefor.phar --exec="/usr/bin/php /data/app.php" --delay=5

指定观察的扩展名

--ext 默认为 php,json,当需要观察其他扩展名时可配置。

php swoolefor.phar --exec="/usr/bin/php /data/app.php" --ext=php,json,ini

重启时发送的信号

程序重启时终止进程是通过给进程发送信号完成的,当我们需要指定信号时。

--signal 默认为 15

php swoolefor.phar --exec="/usr/bin/php /data/app.php" --signal=1

常用的信号表

信号
SIGTERM 15
SIGKILL 9
SIGHUP 1
... ...

支持流行的 Swoole 框架

  • MixPHP:
php swoolefor.phar --exec="/usr/bin/php /data/bin/mix.php web"
  • Hyperf
php swoolefor.phar --exec="/usr/bin/php /data/bin/hyperf start"
  • Swoft:
php swoolefor.phar --exec="/usr/bin/php /data/bin/swoft http:start"
  • EasySwoole:
php swoolefor.phar --exec="/usr/bin/php /data/bin/easyswoole start"
  • laravel-s
php swoolefor.phar --exec="/usr/bin/php /data/bin/laravels start"

License

Apache License Version 2.0, http://www.apache.org/licenses/

About

监控你的 Swoole 程序文件变化并自动重启服务器 - 适用于开发 / Monitor for any changes in your swoole application and automatically restart the server - perfect for development

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages