Closed (fixed)
Project:
Drupal core
Version:
x.y.z
Component:
base system
Priority:
Critical
Category:
Bug report
Assigned:
Reporter:
Created:
15 Jan 2006 at 17:59 UTC
Updated:
6 Feb 2006 at 12:31 UTC
Jump to comment: Most recent file
$_GET['q'] is not properly initialized when serving cached pages. The following code is unreachable when serving a cached page:
// Initialize $_GET['q'] prior to loading modules and invoking hook_init().
if (!empty($_GET['q'])) {
$_GET['q'] = drupal_get_normal_path(trim($_GET['q'], '/'));
}
else {
$_GET['q'] = drupal_get_normal_path(variable_get('site_frontpage', 'node'));
}
This results in statistics_exit() not counting reads from anonymous users in presence of a path alias. The check if ((arg(0) == 'node') && is_numeric(arg(1)) && arg(2) == '') { (from statistics_exit())will fail when a path alias is active. In that case, arg(0) will be 'my-path-alias' and not 'node'. The solution is to move the initialization code, however, it introduces some database overhead.
| Comment | File | Size | Author |
|---|---|---|---|
| #27 | arg.patch | 229 bytes | chx |
| #22 | path.inc_4.patch | 15.31 KB | chx |
| #19 | path.inc_3.patch | 14.91 KB | chx |
| #18 | path.inc_2.patch | 9.72 KB | chx |
| #16 | init_path_0.patch | 6.11 KB | Jaza |
Comments
Comment #1
dries commentedComment #2
chx commentedAs far as I can remember, two people have fiddled with the bootstrap process: moshe and me. $_GET['q'] init code was in common.inc before the bootstrap rehaul which was not included when serving cached pages.
Therefore, I am turning to moshe -- what do you think?
Comment #3
dries commentedMaybe we need to introduce a function, that contains this code. Then the function can be called from statistics_exit(), as well as from the current location. If the statistics.module is not enabled, you won't suffer from any overhead. Slightly uglier code-wise, but faster execution-wise.
Comment #4
moshe weitzman commenteda new function makes sense. no time to do a full review right now.
Comment #5
dries commentedGoing to bump the priority of this. It doesn't break your site, however, it does render statistics.module semi-useless.
Comment #6
Crell commentedAsk and ye shall receive.
I'm not 100% happy with the function name, but it basically just moves that block out to a static-cache run-once function, and then calls it from both _drupal_bootstrap_full() and statistics_exit(). Total performance cost: 1 function call, 2 if statistics is enabled.
Comment #7
chx commentedThis function should live in bootstrap. And it'll bring in some other functions from common.inc . But somewhere we should stop the growing of bootstrap. It was 644 lines in 4.6 and now it inches towards 900 lines. We know it's a performance hit to tokenize all that. Therefore I moved all these to path.inc and introduced a new bootstrap stage. if you are not running stat module then it'll be a performance boost without a doubt.
Comment #8
chx commentedAnd I moved page_set_cache to common -- if you are serving cached pages you do not want to set the cache. You only to want set the cache if you have already built it.
Comment #9
chx commentedEven one more thing -- yes, I discussed this w/ moshe. The name path.inc was even suggested by him.
Comment #10
chx commentedMy form.inc changes sneaked in.
Comment #11
dries commentedI'll go with Crell's patch and leave path.inc for 4.8. Looks like it needs to be rerolled then.
Comment #12
chx commentedBut Crell's patch won't work. He adds the function common.inc and that's not included. And you'll need to move drupal_get_normal_path to bootstrap as well. That does not sound good. I will try to benchmark a cached situationw/ 4.6 and HEAD but I can't promise anything, when I tried benching it fluctuated so widely that it was unusable.
Comment #13
Jaza commentedUpdated chx's patch to have full doxygen comments for each function in path.inc. Apart from that, it looks good. Only, now that Dries has refused path.inc for 4.7 (quite understandable), looks like I'll have to update Crell's last patch instead.
Comment #14
chx commentedNot so fast. He promised a revisit :)
Comment #15
Jaza commentedHere's Crell's patch, updated to work fully within the bootstrap system. This has been submitted instead of the path.inc patch. This patch is not ideal for performance, as it unnecessarily includes in bootstrap the 7 functions that have been moved (in chx's patch) to path.inc. But I'd rather see this get in core (and at least fix the problem), than see nothing get in for 4.7 (in which case statistics.module will be broken for cached sites).
This patch also implements chx's idea of moving page_set_cache() to common.inc.
Comment #16
Jaza commentedAnd now for the patch.
Comment #17
dries commentedUpon re-investigating Chx's patch, I think we should create a path.inc. Sorry for the extra work.
Does anyone happen to have performance numbers for this change?
Comment #18
chx commentedI can't bench, sorry, I am getting numbers like 908+-615 ms which is totally useless. Updated patch though -- drupal_init_path was called in _drupal_bootstrap_full instead at the DRUPAL_BOOTSTRAP_PATH stage.
Comment #19
chx commentedI left out path.inc , repatch.
Comment #20
dries commentedThis patch reduces the size of bootstrap.inc by 20%. The patched bootrap.inc is still 20% bigger than the one in Drupal 4.6. If you have the statistics module enabled, the bootstrap code is 40% bigger than the one in Drupal 4.6.
Comment #21
dries commentedDid some benchmarks. The new code (patch.inc) seems to be 2-3% slower when statistics are enabled, and is equally fast when statistics are disabled. 2-3% is still within the error-marge but it was consistent behavior across multiple tests. Not what I expected ... Anyone else? To reproduce, access a node page (?q=node/x) because that is when the statistic counters are executed.
Comment #22
chx commentedI used a + where there is no doubt that it's needed for cached pages.
New patch: changed timer_stop to be shorter.
Comment #23
chx commentedDries, care to share how you tested? I tried ab localhost without any good result.
Comment #24
moshe weitzman commentedI tested this patch for anon and registered users which page cache was enabled. all works well. code looks good too.
since it fixes the bug described here, lets promote to 'ready to commit'
Comment #25
dries commentedI benchmarked again to double-check, and Crell's patch is slightly faster. Regardless, I committed chx's patch because it is conceptually cleaner and potentially beneficial in future. The slowdown is 2-3ms per requests, probably the extra overhead of opening a file.
Comment #26
tomsys commentedHello,
Using CVS from HEAD
..after this .patch .. now there is a warning on http://www.my_drupal_site.com/node/add page
warning: array_key_exists(): The first argument should be either a string or an integer in <br />/home/www/my_drupal_site/htdocs/modules/node.module on line 1733.Just to let you know
T.
Comment #27
chx commentedHow the....? Now, there is a return FALSE at the end of arg but for my life I can't figure out why I put it there. Once again, I suspect gremlin involvement.
Comment #28
dries commentedCommitted! Thanks.
Comment #29
tomsys commentedThank You :)
T.
Comment #30
(not verified) commented