I'm looking into enabling aggressive caching mode on a site of mine. One of the modules that may stop working properly, is the droptor module. It seems hook_init() is necessary only to know the script's start time. This could be worked around by moving the code out of the function, directly into the module's PHP code:

global $script_start_time;
$script_start_time = microtime(true);

instead of

function droptor_init() {
  global $script_start_time;
  $script_start_time = microtime(true);
}

However, I have no idea how we could still keep the memory monitoring that resides in hook_exit() operational while enabling aggressive caching. Do you have any suggestions?

Comments

jemond’s picture

Assigned: Unassigned » jemond
Status: Active » Closed (works as designed)

Hi Wim,

Thanks for your note.

First off, it looks like I need to move hook_init() to hook_boot(), as hook_boot() is run for normally cached pages but hook_init() isn't. Your note made me realize this, so thanks! (This is now committed to the v3 branch.)

As for supporting aggressive caching (AC) and memory logging, this isn't possible. AC by design skips hook_boot() and hook_exit(), which are vital to make memory logging work. However, Droptor will still work fine with aggressive caching, you just won't get additional memory data for anonymous traffic.

I also don't want to move the start time outside of a module function as I think this isn't Drupal best practices, if I understand correctly.

Kindly let me know if you have any other questions or if there is anything else I can do to help.

Thanks,
jpe

wim leers’s picture

Status: Closed (works as designed) » Active

Heh, glad to unconsciously be of help :)

And thanks for confirming what I thought. I think you may want to document this. I'm going to go ahead and enable aggressive caching on http://driverpacks.net — this will indeed remove many of the memory reports, but that's okay, because there's less PHP involved anyway, that way.

However, now that I think of it, why can't you just use drupal_register_shutdown_function() (or just PHP's own register_shutdown_function() instead? That would *always* work. That's how devel does it, too.

jemond’s picture

Hi Wim,

That is a neat idea. I hadn't thought of that.

I will see if I can get this into the next version of the module. Will update.

jpe

wim leers’s picture

Ok, great! Thanks! :)

xjm’s picture

Regarding using drupal_register_shutdown_function() -- where could you register it that it would still get registered with aggressive caching enabled?

wim leers’s picture

xjm’s picture

Which gets skipped with aggressive caching. :)

wim leers’s picture

Then I don't know/remember :)

However, AFAIK devel works with aggressive caching. We need to verify that. If it's true, then we just need to clone devel's approach.