Laravel-swoole: Hot Reload

Created on 1 Jun 2018  ·  14Comments  ·  Source: swooletw/laravel-swoole

I skimmed through the docs but could not find any thing regarding the Hot Reload. Looks like another library is offerring it out of the box using the inotify php extension. Do you intend to support it if currently not available?

Here it is:
https://github.com/scil/LaravelFly

This is more of a question that's why I am not able to provide the detail here apologies for that.

enhancement suggestion

Most helpful comment

Hi @scil ,

Thanks for your compliment, let me make a brief explanation about the sandbox in this package. First, all the requests will be processed by a sandbox app cloned from the original app container to prevent any data pollution. Besides, this package will replace related container bindings to sandbox. There are two simple charts about this process.


All 14 comments

Hi @aftabnaveed ,

The feature of hot reload is in my develop schedule. But I plan not to implement that with inotify because it doesn't support Mac OSX.

I'm thinking to write a simple node.js script to monitor code changes. Any other suggestions are welcome.

I understand but inotify is quite fast and I think having a fallback node.js support would make more sense. I am reviewing the code right now and will see if I can create a pull request for that.

Hi @aftabnaveed ,

I have created another repo for watching module. You can check swooletw/watcher for more details.

In my personal opinion, I would like to keep hot reload feature separate from this package. Because basically users only need this feature in develop. Also, users needs to install another php extension if I integrate inotify to this package, and Mac OS doesn't support inotify either.

In swooletw/watcher there are only 60 lines in the main script file. It's pretty easy for users to customize according to their needs.

Great work, but I think people like to have a FullStack approach. Instead of a running a separate watcher written in node would it not make more sense to have it enabled when app is in dev mode?

Hi @aftabnaveed ,

I will try to integrate inotify in the near future. Maybe after the coroutine branch is finished.

I'm the author of LaravelFly , I think hot reload is useless in most time, we can use php-fpm in dev.

By the way, laravel-swoole is great, I add it to 'similar projects' in LaravelFly readme and make a simple intro to dif. Welcome read and fix.

Hi @scil ,

Thanks for your compliment, let me make a brief explanation about the sandbox in this package. First, all the requests will be processed by a sandbox app cloned from the original app container to prevent any data pollution. Besides, this package will replace related container bindings to sandbox. There are two simple charts about this process.


@albertcht Thank you! I've update the intro.

好复杂,能不能集成在master里面
用watcher报错
npm安装的
fs.js:646
return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode);
^

Error: ENOENT: no such file or directory, open '/home/wwwroot/xxx/node_modules/chokidar/node_modules/anymatch/node_modules/micromatch/node_modules/braces/node_modules/to-regex/node_modules/regex-not/node_modules/extend-shallow/node_modules/is-extendable/node_modules/is-plain-object/node_modules/isobject/index.js'

开发环境下热更新直接设置成 worker_num=1 max_request=1即可

Why you don't want to integrate autoreload with inotify. I use mac os, but i use docker to run swoole...

The reason I don't prefer inotify has been listed on the above discussion. Currently swoole-watcher is a workable solution for hot reload and it's cross-platform.
Also, I'm busy working on my job these couple months. However, in my first priority for this package, I will still try to finish the coroutine feature and add more tests for better maintainability.
If you believe inotify is a must solution for your hot-reload purpose, a PR with that is welcome anytime.
I will close this issue first. Welcome to open another one if you have any other ideas.

Built-in hot reload feature has been supported in the release v2.6.0. Many thanks to @fractalzombie !

| PHP Version | 7.2.7 |
| Swoole Version | 4.3.3 |
| Laravel Version | 5.7.28 |
| Listen IP | 0.0.0.0 |
| Listen Port | 1215 |
| Server Status | Offline |
| Reactor Num | 4 |
| Worker Num | 1 |
| Task Worker Num | 0 |
| Websocket Mode | Off |
| PID | None |
| Log Path | /app/laravel-swoole/storage/logs/swoole_http.log |
+-----------------+--------------------------------------------------+

Hello, Why do I have to set worker_num=1 max_request=1, Hot reload Take effect?

Was this page helpful?
0 / 5 - 0 ratings