zendframework / zend-expressive-swoole

Swoole support for Expressive applications
BSD 3-Clause "New" or "Revised" License
158 stars 14 forks source link

Added hot code reloading #60

Closed samuelnogueira closed 5 years ago

samuelnogueira commented 5 years ago

Added hot code reload feature.

weierophinney commented 5 years ago

@samuelnogueira This looks awesome!

Are the tests running for you locally? They're erroring on Travis, which makes me wonder if a) you ran the full test suite, or b) we need to bump the swoole version we test against, and/or c) we need to ensure the inotify extension is installed via our travis configuration. Can you investigate, please?

michalbundyra commented 5 years ago

@weierophinney tests are failing on the last master as well - the fix I provided in my PR: https://github.com/zendframework/zend-expressive-swoole/pull/56 (we discuss about it on slack couple weeks ago.... 😃)

weierophinney commented 5 years ago

@samuelnogueira I rebased and pushed back to your branch; let's see if this helps the tests. :smile:

samuelnogueira commented 5 years ago

@weierophinney, @webimpress this is great, thank you! Tests are passing, but InotifyFileWatcherTest is being skipped because inotify extension is missing in the Travis builds.

huangzhhui commented 5 years ago

I use inotify implemented this feature in other framework before, I remember inotify does not work on Docker environment, like Docker for Windows

weierophinney commented 5 years ago

I use inotify implemented this feature in other framework before, I remember inotify does not work on Docker environment, like Docker for Windows

Indeed; however having something is better than nothing here, and we can right up recommendations for folks who are on platforms that do not support inotify.

In particular, none of the various debugging/profiling extensions work with Swoole currently, so one recommendation I've made is for developers to use the internal web server or a docker container that uses a web server + php-fpm during development. When doing so, they will need to ensure that any functionality that normally makes use of Swoole is disabled or adapted for a non-Swoole environment, so they will not be able to debug everything; however, they can debug and profile most everything.

I feel the same is true for inotify usage here: if your environment supports it, it can be a useful development aid as you work on existing handlers and middleware, but it comes with substantial caveats.

grizzm0 commented 5 years ago

I got this working in docker using inotify-proxy. Sadly this screws up PhpStorm as it touches the files outside of PhpStorm and PhpStorm keeps complaining that the file on disk and in memory have conflicts.

COPY .docker/src/inotify-proxy.cpp inotify-proxy.cpp
RUN apk add --no-cache --virtual .build-dependencies autoconf g++ make zlib-dev && \
    g++ inotify-proxy.cpp -o /bin/inotify-proxy && \
    pecl install swoole-4.2.13 inotify && \
    docker-php-ext-enable swoole && \
    docker-php-ext-enable inotify && \
    apk del .build-dependencies

Would be cool if we could trigger the inotify event without actually touching the file. Never used inotify before so I don't really know how it's internals work.

grizzm0 commented 5 years ago

Nvm.. It doesn't seem to work at all.

samuelnogueira commented 5 years ago

Well, for PhpStorm, I guess you can try setting up a File Watcher (under Settings > Tools) with something like this: image This is assuming the PID for the swoole master is 1, there should be some elegant way to find it dynamically.

grizzm0 commented 5 years ago

Thanks..

This did the trick for me. screenshot 2019-02-22 17 22 25

weierophinney commented 5 years ago

@grizzm0 or @samuelnogueira — could one of you open a PR to add a section to the documentation covering this, please? I'm sure others will find it useful as well.