(I'm not a internals developer, but here are some ideas:) 1: I have seen an extension which allows functions/classes to be redefined, although I can't remember what it is called.
2: It is possible to dynamically reload code if defined as anonymous classes or functions using return include: <file_1.php> <?php return class { function some_function($a, $b) { return $a + $b; } }; <file_2.php> $class = include "file_1.php"; $class->some_function(1,2); ---------------- This would entail creating a custom namespace system, and a facility to watch and re-include files. I don't know if the old bytecode of 'orphaned' objects would be garbage collected. 3: Another option would be to create a watcher on the files and just kill and reload the php process on file changes. This would be easier if the application state is all stored externally. 4: Use Ruby/JS/Python instead? On Mon, 18 Mar 2019 at 20:16, Rasmus Schultz <ras...@mindplay.dk> wrote: > > Hello internals, > > How hard would be to add an unload (or reload) feature for > classes/interfaces? > > I'm wondering with regards to running PHP as a deamon (with Swoole or > ReactPHP, etc.) could it be made possible to hot-reload e.g. for > controllers and view-models? > > Of course, the other option is to launch worker sub-processes under some > sort of host process, and then restart the workers after a change - this > adds communication overhead between the host/worker processes though, and a > layer of complexity. > > Another option is if a reverse proxy (NGINX maybe) could restart the actual > application daemon, but that means you have a dependency on a specific > reverse proxy. > > So I know there are other options, but I'm looking for the simplest and > cleanest way to do this, and I'd prefer to stay within the language. > > Other dynamic languages (where daemonizing is "normal", like Ruby, JS and > Python) have this feature and it is often used to hot-reload > controllers/views in web-apps. > > Any thoughts? -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php