Hot Reload For Server #86
Replies: 4 comments 11 replies
-
@tauseefsshah Thanks for bringing this up, I agree that hot reloading the source code would be a nice feature! At the moment, the easiest work around is to use PHP's development web server for development purposes and the built-in web server for production use: # development (reloads source for every request)
$ php -S localhost:8080 public/index.php
# deployment (keeps everything in memory)
$ php public/index.php X supports running anywhere and we can take advantage of this for development purposes as both modes can be used mostly interchangeably. Longer term, we're definitely interested in bringing in hot reloading also for the built-in web server. Unfortunately, this is non-trivial as checking the filesystem is inherently blocking and as such rather costly. Periodically spawning a child process (how often?) only for this purpose seems quite excessive; taking advantage of inotify might be option, but either requires an extension or FFI, so I'm not sure how feasible this is. We've also discussed an option to use a filesystem monitor in sytemd to restart the service unit if that's your cup of tea. Many options… Would love to hear more input on this! 👍 |
Beta Was this translation helpful? Give feedback.
-
I use https://github.com/seregazhuk/php-watcher and It works fine. |
Beta Was this translation helpful? Give feedback.
-
Small update: I've started working on this and have a working prototype ready: See https://twitter.com/another_clue/status/1545359689961144320 Current focus is to detect changes for included files which already works just fine. Once changes are detected, the process is restarted. The server socket will temporarily be paused without closing and will be reused in the new process, so there should be zero downtime. However, we should also properly handle any active connections that may exist when a change is detected. The idea is to soft-close any connections and have a fallback to kill any remaining connections after a second. This is doable for all incoming connections, but similar logic should also trigger for any outgoing connections (think an idle connection to your database). PHP lacks low-level system access, but we may utilize FFI (optional, PHP 7.4+) to close any remaining connections. I'll try to keep this updated as we make progress 👍 |
Beta Was this translation helpful? Give feedback.
-
What about entr? From the public/ dir...
Should restart X whenever anything in public/ changes. |
Beta Was this translation helpful? Give feedback.
-
Just got my hands on the framework and while trying out stuff I felt the need for a hot reloading server because it's a very handy and a convenient feature to have. I feel having to restart the server after every code change is inefficient.
I might have missed it but if there's a way to achieve it, I'll appreciate you sharing.
Beta Was this translation helpful? Give feedback.
All reactions