Make WordPress Core

Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#26804 closed enhancement (invalid)

Support multiple $wpdb handlers

Reported by: mgibbs189's profile 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)

load.php.patch (577 bytes) - added by mgibbs189 11 years ago.
load.php.2.patch (572 bytes) - added by mgibbs189 11 years ago.
Better VCS support
wp-settings.php.patch (771 bytes) - added by mgibbs189 11 years ago.

Download all attachments as: .zip

Change History (15)

@mgibbs189
11 years ago

#1 @johnbillion
11 years ago

  • Keywords reporter-feedback added

Could you provide an example of how this would be used? db.php files instantiate the wpdb 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.

#2 @mgibbs189
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.

Last edited 11 years ago by mgibbs189 (previous) (diff)

#3 @mgibbs189
11 years ago

  • Keywords reporter-feedback removed

#4 @wonderboymusic
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.

@mgibbs189
11 years ago

Better VCS support

#5 @markoheijnen
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.

Last edited 11 years ago by markoheijnen (previous) (diff)

#6 @mgibbs189
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
Last edited 11 years ago by mgibbs189 (previous) (diff)

#7 @wonderboymusic
11 years ago

you're describing advanced-cache.php

#8 @mgibbs189
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 @mgibbs189
11 years ago

Attached is another solution (wp-settings.php.patch). It checks for custom shortinit handlers before exiting.

Last edited 11 years ago by mgibbs189 (previous) (diff)

#10 @mgibbs189
11 years ago

  • Keywords close added
  • Resolution set to invalid
  • Status changed from new to closed

Closing - moving to a new ticket since this now deals less with $wpdb.

#11 @johnbillion
11 years ago

  • Milestone Awaiting Review deleted

#12 @DrewAPicture
11 years ago

@mgibbs189's new ticket is here: #26806

Note: See TracTickets for help on using tickets.