Reload php module with require()
Posted: Mon Jan 18, 2010 1:02 am
Hello,
I have a php application that when it starts it dynamically loads "custom" modules found in a specific folder (custom folder); the application loops through the .php files in the custom folder and does a require() on each .php file to load it. The custom modules get registered within the application and the methods with them are callable. This is basically a chat interfacing application and the new features loaded from the custom modules can be accessed by chat calls.
Now what I am trying to do is reload an existing module if the module is changed/updated. I have a cron loop (within the main application) that watches the timestamps of the files in the custom folder and if any change then it does a require() on that .php file to reload it. This all works, ie - no errors, however the reloaded module file does not appear to overwrite/replace the first version of the .php file; calling a method from the file returns the same response after the reload as it did when it was first loaded.
So, can a module that was loaded with require() be loaded a second time with another call to require() and have its new/changed methods replace the first loaded version? Is there a way to unset/dealloc the modules and its methods before reloading it?
Thanks!
I have a php application that when it starts it dynamically loads "custom" modules found in a specific folder (custom folder); the application loops through the .php files in the custom folder and does a require() on each .php file to load it. The custom modules get registered within the application and the methods with them are callable. This is basically a chat interfacing application and the new features loaded from the custom modules can be accessed by chat calls.
Now what I am trying to do is reload an existing module if the module is changed/updated. I have a cron loop (within the main application) that watches the timestamps of the files in the custom folder and if any change then it does a require() on that .php file to reload it. This all works, ie - no errors, however the reloaded module file does not appear to overwrite/replace the first version of the .php file; calling a method from the file returns the same response after the reload as it did when it was first loaded.
So, can a module that was loaded with require() be loaded a second time with another call to require() and have its new/changed methods replace the first loaded version? Is there a way to unset/dealloc the modules and its methods before reloading it?
Thanks!