Closed (fixed)
Project:
Better Statistics
Version:
7.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
4 Jan 2013 at 01:28 UTC
Updated:
4 Feb 2013 at 07:20 UTC
Jump to comment: Most recent file
Comments
Comment #1
mondrakeAfter some trials, I tend to think that this case requires dedicated focus while developing the integration plugin.
Out of experience with two modules I developed some integration for, 'Browscap' and 'IP Geolocation Views and Maps':
drupal_get_path()won't work (see #1839090: Call to undefined function drupal_get_path())module_load_include()won't workrequire_once dirname(__FILE__) . '/path/to/yourmodule.module';, and ensure that any chained inclusion follow the same logic (i.e. you cannot have a module_load_include() in the file you include through require_once...)hook_initimplementation that would normally 'do something' and be triggered at module load, would need to be explicitly called by the plugin in case of cached page (this is the case for ip_geoloc)With this said, I believe options 2 and 3 above would fall short anyway (#2 because if developer is not checking all the possible implications, dependencies, etc, the entire call would fail, #3 because you would miss the function calls of hook_init). It is really a matter of developing the statistics plugin callback in such a manner that it can cope with cached page requests.
My ideal scenario is as follows (I do not know if this is all possible, but let's dream :)):
hook_statistics_api()to declare if the module is capable or not of collecting data for cached page requests. By default, NOT. Better Statistics should use this to decide whether or not to call the callbacks of the module at runtime.Cheers
Comment #2
mondrakeI just realised an alternative could be to call
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);if we are serving a cached page. But that would slash any benefit of caching I believe.EDIT:
However, calling that bootstrap phase during hook_exit can lead to nasty issues like
if the called module's hook is trying to write to the returned page (I guess that's because in a caching concern the request has been executed and returned already)...
Comment #3
iamEAP commentedHmm... I think I'd like to avoid complicating the API much further.
I wonder if, rather than bootstrapping Drupal further, it would be sufficient to always include common.inc. I'd bet a majority of functions required would be found in there, though there may be some cases where a function in common.inc relies on a function elsewhere...
Comment #4
mondrakeI'd leave that to the plugin developer, in order not to load Better Statistics with unnecessary overload.
For instance, I ended up including that for the IP Geolocation plugin (it is working now), as one dependency requires also drupal_http_request()
Comment #5
iamEAP commentedI have a feeling there won't really be a clean, friendly way to solve this problem. Someone's going to have the feel the burden eventually, and I think it's better to pass it to developers (to ensure their code works for both cached and uncached requests) than to site builders (who may not necessarily understand or want to understand caching).
With that being said, can we move forward with providing better documentation to developers? This might be a good opportunity to create some documentation pages on d.o.
Comment #6
mondrakeI tend to agree :), I am also proposing to change the issue title here.
Just a few free thoughts for your consideration, iamEAP:
Comment #7
iamEAP commentedI think #1 would be a good idea, but probably rolled in as part of #1879726: Should statistics be collected on every page? (in addition to path-based and role-based inclusion). Though it might make sense to include this on the performance configuration page rather than the statistics configuration page.
I think #2 is also probably a good idea. I don't know the best way to hand off the info. We'd have to break the API to include the info as part of the call to the respective field data callback. Suppose we could provide a function that modules can call like better_statistics_cache_status() or something like that.
I believe the only reason it's necessary is because accesslog stores a session ID and DRUPAL_BOOTSTRAP_SESSION is required to gain access to that information.
Comment #8
iamEAP commentedHere's a patch that:
better_statistics_served_from_cache()that returns TRUE for cache hit, FALSE for cache miss, and NULL for uncacheable,For your purposes, the function returning FALSE vs. NULL doesn't matter much, since in both of those cases, Drupal's bootstrap phase should be full.
Comment #9
iamEAP commentedPatch...
Comment #10
mondrakeMaybe I am paranoid.... but theoretically better_statistics_served_from_cache() could be invoked before headers are fully sent, so freezing the value of the static variable in the function. I changed that to include a switch to force scanning the headers, and included a call at the beginning of better_statistics_exit() - so to make sure cache status returned is the one relevant at that point.
Maybe with that the following code could become conditional on $cache_status === TRUE??
Comment #11
iamEAP commentedThat's actually a good point. We may as well just get rid of the static caching entirely.
Comment #12
iamEAP commentedAh, actually, nevermind.
The headers_list() function will return all headers regardless of whether they've been sent or not. Static caching is probably a good idea, still. Disregard #11.
Some confusion might come from the fact that there isn't necessarily any correlation between cache status and bootstrap phase. If what you want to know is the current phase, calling drupal_bootstrap() should return the phase. The call to bootstrap to the session phase in hook_exit() incurs very little overhead on uncached pages because it would just be a no-op (drupal_bootstrap would see that Drupal's already bootstrapped to a higher phase and just return).
Comment #13
mondrakeI prefer to have static as module plugins will likely call the function in the callbacks to determine how to return the field value.
So either patch in #9 or in #10 are ok with me. The #10 will just make sure that even if better_statistics_served_from_cache() is called before the headers are built, the status of headers at hook_exit is checked.
Comment #14
iamEAP commentedThanks, mondrake. Committed #10 with small changes to comments.
http://drupalcode.org/project/better_statistics.git/commit/a74ae36