Re: Unload/reload included class

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Jan 4, 2011 at 4:44 PM, Patrik Pomichal
<patrik.pomichal@xxxxxxxxx>wrote:

> Loading plugin is easy, when my app found new file in plugins dir,
> include and register it. But if i change the plugin source i must restart
> the app to reload it.


If you don't mind the resource burn (memory) of loading a lot of code over
time without flushing it out when not needed, you could have the plugin
files contain the methods without the enclosing class declaration. When you
(re)load a plugin, you create a dynamic class name using a counter or some
other uniqueness mechanism, build a string containing a class declaration
wrapped around the file's contents, and use eval() to load it.

You could of course let the coder put a class name into the plugin file if
that looks nicer and do a string replace on it with your dynamic name. The
key is that you cannot unload classes in PHP AFAIK so you must come up with
a new class name each time. The old compiled bytecode will remain, but you
can destroy the old plugin instance to regain a little memory.

David

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux