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!
Reload php module with require()
Moderator: General Moderators
Re: Reload php module with require()
The module should be changed to do its work dynamically. You shouldn't have to modify the module code itself.
Re: Reload php module with require()
Understood ... and if I implied that I was just wanting to change some hard coded values and then reload the module, I would agree with you.
However the intention is not that. What it really is is that I am still developing the module; the main application is a pain to have to stop it and restart it each time I tweak the custom module that is still under development. Basically, as I test it and modify the code and save/update the .php file, I'd like it to be reloaded rather than have to stop and restart the mother application.
However the intention is not that. What it really is is that I am still developing the module; the main application is a pain to have to stop it and restart it each time I tweak the custom module that is still under development. Basically, as I test it and modify the code and save/update the .php file, I'd like it to be reloaded rather than have to stop and restart the mother application.
- SimpleManWeb
- Forum Commoner
- Posts: 57
- Joined: Wed Dec 30, 2009 4:15 pm
- Location: New Hampshire, USA
Re: Reload php module with require()
I'm not saying it's not possible, but i'm pretty savvy with PHP and I don't know of any way to do it.
Sorry
Sorry
Re: Reload php module with require()
Thanks, SimpleMan; I had previous gotten that same type of response from another devlopment system, though they weren't 100% sure either. So I guess you answer and theirs make it official.
Regards.
Regards.