#26804 closed enhancement (invalid)
Support multiple $wpdb handlers
Reported by: | mgibbs189 | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 3.9 |
Component: | Database | Keywords: | dev-feedback close |
Focuses: | Cc: |
Description
A handful of plugins (W3 Total Cache, Query Monitor, etc.) use /wp-content/db.php
for caching or query debugging. Unfortunately, only a single plugin is able to use it at once.
This patch allows multiple plugins to access WP at this stage of execution. Custom handlers can be placed into a /wp-content/db/
folder.
Attachments (3)
Change History (15)
#2
@
11 years ago
- Keywords dev-feedback added
Sure - I'm building AJAX caching for a plugin, and need access to WPDB as early as possible. The normal admin-ajax.php
routine fully loads WP and all plugins, which in this case is unnecessary (every millisecond counts).
My use case: https://gist.github.com/mgibbs189/8345521
- A request is made to admin-ajax.php
- Load WPDB if it doesn't exist already
- Using WPDB, check to see if a cached version exists...
- If YES, output the cached version and EXIT
- If NO, continue loading WP
This patch will help any plugin needing to implement DB-based (ajax) caching.
#4
@
11 years ago
- Keywords close added
since wp-content/db.php
is a drop-in controlled by the user, why don't you just put your code in there? or why don't you add the logic to advanced-cache.php
? Seems like your only need is to load early. If you are using multisite, add your logic to sunrise.php
- even for single site, turn multisite on and add it to sunrise.php
and exit()
after conditionally. OR, access your PHP file directly from AJAX and do something like:
define( 'SHORTINIT', 1 ); require( 'wherever/wp-load.php' ); // load your special file thing // do whatever
OR just bail on init
.
#5
@
11 years ago
I agree with johnbillion and wonderboymusic here. The code doesn't solve the issue. It instead it will be more confusing since a normal db.php will set $wpdb
and you can't control which file is going to set the variable as last.
Your use case doesn't show the need of multiple db classes. You miss use the file to execute code that doesn't involve the db handler.
#6
@
11 years ago
- Keywords close removed
@markoheijnen - That's true, the timing could make things confusing, but I need some way to include a caching handler before WP and all the plugins fully load. In some cases, this is the difference between 20ms and 2 seconds.
@wonderboymusic's suggestion to use SHORTINIT
with wp-load.php
won't work because it FORCES WP to quit early. I need a way for this to happen conditionally. E.g.
- If a cache exists, then simulate
SHORTINIT
(quit early) - If cache doesn't exist, then continue normal execution
#8
@
11 years ago
@wonderboymusic - that's the problem. Only 1 plugin at a time can use advanced-cache.php, object-cache.php, or db.php. Plugins like W3 Total Cache register all of these files.
My plugin needs to work side-by-side with W3 Total Cache. W3 Total Cache isn't able to cache ajax requests. Hence the need for multiple handlers.
#9
@
11 years ago
Attached is another solution (wp-settings.php.patch). It checks for custom shortinit
handlers before exiting.
Could you provide an example of how this would be used?
db.php
files instantiate thewpdb
class and assign it to$wpdb
. If more than one file that did this was loaded, it wouldn't solve the problem because each one would override the previous one's$wpdb
.