I am an experienced developer, but I have never worked with Drupal. I have been employed to make a couple of small cosmetic changes to an existing module, which has been installed on an existing Drupal installation. I have found the code that needs to be changed, in a .module file. If I alter that code, the resulting change is not apparent on the website. If you modify a .module file for an installed module, is there some additional action needed to force Drupal to reload the .module code? If so, can this action be taken via the Drupal admin interface, or does it require command-line access? Any help would be appreciated. Thanks.

Comments

mbrutsch’s picture

Is there some special codeword needed to get a response here? Is my question posted in the wrong forum?

jamestombs’s picture

I'm new to Drupal, but any changes that I have made to my module while it was activated occurred immediately.

I can only assume you either changed some code which isn't being used on the page you are testing, your code doesn't work as expected or your code is operating in some way which requires some changes to be made to Drupal such as the cache. If it is indeed the cache, if you go in to your MySQL database, and truncate the cache tables, and see if the problem continues.

Action Medical Research - www.action.org.uk

James T
Action Medical Research - www.action.org.uk

criznach’s picture

If you're doing any Drupal coding you'll want to install the Devel module and enable the Devel block.

http://drupal.org/project/devel

It has an "Empty Cache" button so you can clear the cache whenever you want. Disable and remove it from production sites, because it enables a lot of powerful features.

Be aware that if you change a module directly you won't be able to easily upgrade it to the next release without patching in your changes and re-testing. If you want this change to be maintainable, consider writing a new module that hooks into the existing one, or if this is a useful change, you could submit your changes to be incorporated into the existing module. You'll see this discussion come up a lot here.

meric’s picture

It should reflect on the page once the browser is refreshed.. If it's just content that is changed, it should take effect after immediately.. But in case of defining new menus, nodes or pages, I normally use menu_rebuild() or module_rebuild_cache()

nancydru’s picture

The menu.inc code generates a "require_once" for all module files using the "file" option. Rebuilding the menu and clearing the cache (using Devel) is not making PHP reload the files. The only way I have found so far is to reboot my machine. This is totally unacceptable to me as a developer; taking 10 minutes to reboot when I spent 10 seconds to make a change just won't cut it.

There must be a better way?

dogo’s picture

I have exactly the same problem.
Sometimes i get the new version by disabling / enabling the module,
sometimes after disabling everything in the menu and enabling it again,
sometimes nothing really helps.
devel modul does not work in this case - or what am i doing wrong ?

vefverksmidja’s picture

Hi,

We at the Uni of Iceland were having the same problem as you guys and it was driving us crazy. After tons of tinkering with all kinds of stuff the solution for us at least turned out to be the APC library (http://php.net/manual/en/book.apc.php).

After turning it off this horrible issue disappeared.

I hope it helps.

best regards, the man who knew too little

jhl.verona’s picture

Very curious. I've been developing with Drupal for a while now, and never had these problems. Or at least not quite these problems. Never had to do the NancyDru solution. Though I can see why APC would cause problems, but why would you need code caching during development?

If you change code inside an existing function, or create a new (non hook) function, the results (usually a syntax error in my case) are as quick as you can refresh the page ;-)

Adding a hook or menu function can cause problems, but refreshing (submitting) the modules list page - admin/build/modules/list - fixes that, because it rebuilds the various module caches. Worst case is to pull the 'Flush all caches' link in devel / admin_menu, which is the equivalent of electroshock for Drupal.

I think NanyDru's problem (probably fixed by now, if she wants to keep her sanity) may also be connected with a code cache. And they are the last thing you need while developing.

Further, when I transfer the modified code to the server (FTP worst case, rsync best case) I can't recall *ever* having had to do anything much, other than devel / admin_menu 'Flush all caches', which has become more or less a reflex action. (Then they both get disabled again in a production environment). In these cases, I usually don't have permission to either restart Apache or the server.

nancydru’s picture

I do not use a code cache, unless PHP has something built in that I don't know about. I only have this problem when the menu says a function is in another file, otherwise updates happen just fine. The problem is that the menu system uses "require_once."

jhl.verona’s picture

Forgive my ignorance of the internals of PHP, but...

/usr/bin//php is an interpreter, so it's slurping in the php files, interpreting them, and executing them - on every HTTP request, right?
Only some of the 'code' is actually stored in the database, such as the active modules and theme registry so these need to be reset occasionally.
Also the Apache thread could be 'storing' the code for later reuse. Maybe even just refreshing php files that have changed.
(This is all guess work, I haven't had the necessity to actually find out)

So if clearing/rebuilding the database code doesn't work, you *might* at worst have to restart Apache.
Otherwise I can only think of a code cache (like APC) needing a reboot of the computer.

Again, forgive my ignorance, but doesn't a "require_once" just mean that the file need not be reloaded if it's already in memory? I've created a few modules with inc files and put 'require_once' in the module file (not quite the scenario you describe, I admit) but I didn't have any problems...

I use Ubuntu with 'standard' php and Apache installations. APC is there in the admin/reports/status/php report, because I added it afterwards. So actually I'm caching code as well, hmm. If you are too, it might be the apc.include_once_override (mine is Off) or the apc.stat (mine is On) parameters that cause the problem (I'm still guessing).
If any of that makes sense, it's because I stole it from this http://www.phpro.org/manual/ref.apc.html

HTH

John

P.S. just added apc.php from /usr/share/php into my drupal sandbox directory, then http://localhost/drupal/apc.php - I *am* caching code after all...

anieves’s picture

Never use require* or include* in .module files, use module_load_include() instead, this work fine and is pure Drupal code.

The problem is in hooks functions that Drupal cache their content (like hook_menu or hook_theme), the only aceptable solution in my case is TRUNCATE 'cache*' direct in db or use drupal rebuild cache functions outside of any function in any .module file (i prefer truncate db).

This solves the problem such that I had when hook_init function was not running.

/* without cleaning the cache, this hook does not run (at least in Drupal 7)
anybody know why this occur? */
mymodule_init() {
  module_load_include('inc', 'mymodule');
}
leozzz’s picture

I have a very simple solution to your problem:

just enter the site configuation

click "module" to enter the module listing page

and then your code will be reloaded.

It's quite a bit tricky that the module listing page causing refresh of .inc , .module code

matayl’s picture

admin > config > development > performance > Clear all caches

tinny2’s picture

If using MAMP then turn off OPCache in php.ini.

See: http://stackoverflow.com/a/19130992