Giter Site home page Giter Site logo

hyperf-watch's Introduction

hyperf-watch

🚀 Hyperf Watch Hot Reload Scripts

😊 Make Coding More Happy

👉 监听文件变化自动重启Hyperf

Author: [email protected]

Tips: 只建议在开发环境中使用,如果对您有帮助,请给项目一个Star,谢谢!

Gitee仓库: https://gitee.com/hanicc/hyperf-watch

使用说明:

建议PHP>=7.2 && Swoole>=4.4,php.ini需要开启exec方法

基于Swoole的Process/Timer/Event实现,定时扫描文件并监听文件变动重启服务

下载文件:

【Windows】

下载完成后请拷贝到项目根目录上:

下载地址->请右键另存为,并删去扩展名.txt

【MacOS or Linux】

在项目根目录下启动终端控制台:

wget -O watch https://gitee.com/hanicc/hyperf-watch/raw/master/watch

启动监听:

php watch

启动监听并删除代理类缓存(./runtime/container):

php watch -c

退出监听:

Control + C

默认配置(打开watch文件,可自行修改):

# PHP Bin File PHP程序所在路径(默认自动获取)
const PHP_BIN_FILE = 'which php';
# Watch Dir 监听目录(默认监听脚本所在的根目录)
const WATCH_DIR = __DIR__ . '/';
# Watch Ext 监听扩展名(多个可用英文逗号隔开)
const WATCH_EXT = 'php,env';
# Exclude Dir 排除目录(不监听的目录,数组形式)
const EXCLUDE_DIR = ['vendor', 'runtime', 'public'];
# Entry Point File 入口文件
const ENTRY_POINT_FILE = __DIR__ . '/bin/hyperf.php';
# Start Command 启动命令
const START_COMMAND = [ENTRY_POINT_FILE, 'start'];
# PID File Path PID文件路径
const PID_FILE_PATH = __DIR__ . '/runtime/hyperf.pid';
# Scan Interval 扫描间隔(毫秒,默认2000)
const SCAN_INTERVAL = 2000;
# Console Color 控制台颜色
const CONSOLE_COLOR_DEFAULT = "\033[0m";
const CONSOLE_COLOR_RED = "\033[0;31m";
const CONSOLE_COLOR_GREEN = "\033[0;32m";
const CONSOLE_COLOR_YELLOW = "\033[0;33m";
const CONSOLE_COLOR_BLUE = "\033[0;34m";

hyperf-watch's People

Contributors

cmpan avatar ha-ni-cc avatar yu1ec avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

hyperf-watch's Issues

修改文件几次后,重启服务就卡主不动,控制台没有信息输出,然后报warning错误

[root@localhost api]# php watch -c
?? Start @ 2020-06-11 06:54:06
?? Watching 78 files...
rm -rf ./runtime/container/proxy
..
Detected an available cache, skip the app scan process.
Detected an available cache, skip the vendor scan process.
[INFO] Worker#1 started.
[INFO] Worker#0 started.
[INFO] HTTP Server listening at 0.0.0.0:9501
[INFO] Worker#2 started.
[INFO] Worker#3 started.
[INFO] Process[queue.default.0] start.
?? Restart @ 2020-06-11 06:54:31
?? Watching 78 files...
rm -rf ./runtime/container/proxy
..
Scanning app ...
Scan app completed, took 1277.706861496 milliseconds.
Detected an available cache, skip the vendor scan process.
[INFO] Worker#1 started.
[INFO] Worker#0 started.
[INFO] HTTP Server listening at 0.0.0.0:9501
[INFO] Worker#2 started.
[INFO] Worker#3 started.
[INFO] Process[queue.default.0] start.
?? Restart @ 2020-06-11 06:54:39
PHP Warning: Swoole\Event::add(): already exist in xxx/api/watch on line 67
?? Watching 78 files...
rm -rf ./runtime/container/proxy
..
Scanning app ...
Scan app completed, took 1277.7030467987 milliseconds.
Detected an available cache, skip the vendor scan process.
[INFO] Worker#1 started.
[INFO] Worker#0 started.
[INFO] HTTP Server listening at 0.0.0.0:9501
[INFO] Worker#2 started.
[INFO] Worker#3 started.
[INFO] Process[queue.default.0] start.
[NOTICE]
TIME:2020-06-11 02:55:11
PERMS:sys:user:list
IP:192.168.33.1
?? Restart @ 2020-06-11 06:55:11
PHP Warning: Swoole\Event::add(): already exist in xxx/watch on line 67
?? Watching 78 files...

Windows 的下载不了

无法访问此网站找不到 raw.githubusercontent.com 的服务器 IP 地址。
尝试运行 Windows 网络诊断。
DNS_PROBE_FINISHED_NXDOMAIN

homestead 下完全不能使用

环境 ubuntu homestead
hyperf 版本 1.0

启动什么的都是正常。但是日志报错

================================
🚀 Start @ 2019-10-08 16:33:41

Scanning ...
Scan completed.
[DEBUG] Event Hyperf\Framework\Event\BootApplication handled by Hyperf\Di\Listener\BootApplicationListener listener.
[DEBUG] Event Hyperf\Framework\Event\BootApplication handled by Hyperf\Config\Listener\RegisterPropertyHandlerListener listener.
[DEBUG] Event Hyperf\Framework\Event\BootApplication handled by Hyperf\Paginator\Listener\PageResolverListener listener.
[2019-10-08 16:33:47 @13188.0] WARNING swSocket_bind(:434): bind(0.0.0.0:9501) failed, Error: Address already in use[98]

In Server.php line 169:

failed to listen server port[0.0.0.0:9501], Error: Address already in use[9
8]

start

换一个端口,报错一个。

使用swoole-cli模式运行时有错

将swoole-cli改名成php并放入环境变量后,执行php watch提示如下错误:

Deprecated: Return type of Filter::accept() should either be compatible with FilterIterator::accept(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /mnt/d/phpstudy_pro/WWW/hyperf-test/watch on line 224
🚀 Start @ 2022-07-23 03:33:23

Fatal error: Uncaught ArgumentCountError: posix_kill() expects exactly 2 arguments, 1 given in /mnt/d/phpstudy_pro/WWW/hyperf-test/watch:83
Stack trace:
#0 /mnt/d/phpstudy_pro/WWW/hyperf-test/watch(83): posix_kill('396')
#1 /mnt/d/phpstudy_pro/WWW/hyperf-test/watch(102): killOldProcess()
#2 /mnt/d/phpstudy_pro/WWW/hyperf-test/watch(75): start()
#3 {main}
thrown in /mnt/d/phpstudy_pro/WWW/hyperf-test/watch on line 83

热加载建议

目前用起来挺方便的,就是遇到一个问题,如果我在修改blade模版,也会触发reload动作,然后我就得等待3秒等它完成reload,可以过滤掉自定义文件后缀的文件监控吗

【建议】默认日志级别的问题

建议:
将log_level的级别调至SWOOLE_LOG_INFO或者以上。

场景:
我编译的swoole,是开启了debug和trace输出的,在执行大佬你的watch命令时,打印了一堆trace日志,我觉得,这种日志,我一个使用者应该没必要看到吧?

CPU使用率过高

cup的使用率一直占用30%,导致电脑容易发热,建议优化下,比入适当的加些休眠时间

启动报错

➜ hyperf-skeleton php watch
🚀 Start @ 2020-02-26 13:40:16
📡 Watching 35 files...

Notice: Use of undefined constant SWOOLE_HOOK_ALL - assumed 'SWOOLE_HOOK_ALL' in /Users/nick/document/code/www/myself/hyperf/hyperf-skeleton/bin/hyperf.php on line 11
Scanning app ...

Fatal error: Declaration of App\Listener\DbQueryExecutedListener::process(App\Listener\object $event) must be compatible with Hyperf\Event\Contract\ListenerInterface::process(Hyperf\Event\Contract\object $event) in /Users/nick/document/code/www/myself/hyperf/hyperf-skeleton/app/Listener/DbQueryExecutedListener.php on line 27

deprecated function

Start @ 2021-05-06 16:46:13
Watching 35 files...
PHP Deprecated:  Swoole\Event::rshutdown(): Event::wait() in shutdown function is deprecated in Unknown on line 0

Deprecated: Swoole\Event::rshutdown(): Event::wait() in shutdown function is deprecated in Unknown on line 0

Call to a member function input() on null

版本:2.1
情况描述:控制器中通过$this->request->input来获取参数,启动监听后获取不了参数,如果用原生的启动是没有问题的
错误情况:
[DEBUG] Event Hyperf\Framework\Event\BootApplication handled by Hyperf\Config\Listener\RegisterPropertyHandlerListener listener. [DEBUG] Event Hyperf\Framework\Event\BootApplication handled by Hyperf\ExceptionHandler\Listener\ErrorExceptionHandler listener. [DEBUG] Event Hyperf\Framework\Event\BootApplication handled by Hyperf\ExceptionHandler\Listener\ExceptionHandlerListener listener. [DEBUG] Event Hyperf\Framework\Event\BootApplication handled by Hyperf\DbConnection\Listener\RegisterConnectionResolverListener listener. [DEBUG] Event Hyperf\Framework\Event\BeforeMainServerStart handled by Hyperf\Process\Listener\BootProcessListener listener. [DEBUG] Event Hyperf\Framework\Event\OnStart handled by Hyperf\Server\Listener\InitProcessTitleListener listener. [INFO] Worker#0 started. [INFO] HTTP Server listening at 0.0.0.0:9501 [DEBUG] Event Hyperf\Framework\Event\AfterWorkerStart handled by Hyperf\Server\Listener\AfterWorkerStartListener listener. [DEBUG] Event Hyperf\Framework\Event\AfterWorkerStart handled by Hyperf\Server\Listener\InitProcessTitleListener listener. [DEBUG] Event Hyperf\Framework\Event\OnManagerStart handled by Hyperf\Server\Listener\InitProcessTitleListener listener. [INFO] Worker#1 started. [DEBUG] Event Hyperf\Framework\Event\AfterWorkerStart handled by Hyperf\Server\Listener\AfterWorkerStartListener listener. [DEBUG] Event Hyperf\Framework\Event\AfterWorkerStart handled by Hyperf\Server\Listener\InitProcessTitleListener listener. [ERROR] Call to a member function input() on null[34] in /data/wwwroot/hyperf-skeleton/app/Controller/IndexController.php [ERROR] #0 /data/wwwroot/hyperf-skeleton/vendor/hyperf/http-server/src/CoreMiddleware.php(161): App\Controller\IndexController->verifyCode()

控制器代码片段
public function verifyCode() { $uuid = $this->request->input('uuid', ''); if(empty($uuid)) { return ['code' => 500, 'msg' => 'uuid is empty', 'data' => []]; } }

hf 更新后失效

更新了最新的hf版本
多次修改代码以后提示这个,然后导致服务直接无法响应
Warning: Swoole\Event::add(): already exist in /var/www/bravo-encode-api/watch.php on line 114

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.