1

Once a PHP object is already loaded on PHP, is there a way to reload it?

The motivation of this question is a PHP watcher in a ReactPHP server. Using ReactPHP, the kernel can be reloaded without having to stopping the server itself, but even if one PHP file has changed, the PHP code is already loaded in memory, and nothing happens.

mmoreram
  • 687
  • 5
  • 13

2 Answers2

0

There is no way to do that, unless you use something like child processes or monkey patching behind a PSR-11 container that hides it behind an interface. The obvious problem is that your memory will increase for every class you load like that. But from the language itself there is no support.

WyriHaximus
  • 1,000
  • 6
  • 8
0

I think with the main functions it isn't working but there are some projects that can implement a hot reloading.

https://github.com/felippe-regazio/php-hot-reloader

Perhaps that is working for your case.

René Höhle
  • 26,716
  • 22
  • 73
  • 82