Reload php module with require()

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
riccarr
Forum Newbie
Posts: 3
Joined: Mon Jan 18, 2010 12:48 am

Reload php module with require()

Post by riccarr »

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!
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Reload php module with require()

Post by requinix »

The module should be changed to do its work dynamically. You shouldn't have to modify the module code itself.
riccarr
Forum Newbie
Posts: 3
Joined: Mon Jan 18, 2010 12:48 am

Re: Reload php module with require()

Post by riccarr »

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.
User avatar
SimpleManWeb
Forum Commoner
Posts: 57
Joined: Wed Dec 30, 2009 4:15 pm
Location: New Hampshire, USA

Re: Reload php module with require()

Post by SimpleManWeb »

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
riccarr
Forum Newbie
Posts: 3
Joined: Mon Jan 18, 2010 12:48 am

Re: Reload php module with require()

Post by riccarr »

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.
Post Reply