Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Doesn't work with WP Super Cache enabled #164

Merged
merged 1 commit into from

5 participants

@pkaeding

I just set up wp-cli version a45bfd0. If I run it from outside my wordpress installation, it correctly prompts me to prove the --path argument. If I run wp --version, I see wp-cli 0.7.0-alpha, so that looks good. However, if I run any other command, either from the WP install folder, or by providing --path pointing to it, all I see is the HTML of my homepage.

Have I just misconfigured something?

@scribu
Owner

Are you sure it's the html of your homepage or a warning that WP isn't installed or something like that?

@pkaeding

No, it is my homepage content. I saved it to a file and opened it in a browser to be sure it wasn't just my site's chrome wrapping an error message or something, but it is actually just the HTML from my home page.

@scribu
Owner

That's weird. Do you have any caching plugins active, like WP Super Cache?

@pkaeding

Yes, as a matter of fact, I do use WP Super Cache. Is this what is causing the problem?

@scribu
Owner

Only way to find out is by removing it, particularly the files in wp-content.

@pkaeding

Okay, WP Super Cache seems to be involved. I disabled the cache, and then wp help returned the expected output.

I don't want to disable the cache, though. I guess I could disable the cache before using wp-cli, and re-enable it afterwards, but that sucks.

Is it possible to have wp-cli not get cached responses?

@pkaeding

Wow, after having just upgraded the core WP code, and a handful of plugins in under 2 minutes (including toggling WP Super Cache off & on), this is amazing! Upgrades have always been a bit of a pain, since I don't like the idea of making the WP installation writable by the user that it runs as.

While I still think it would be great if we could get wp-cli and wp super cache to play well together, this is still an amazing tool! Thanks!

@andreascreten

I did some tests with WP Super Cache and WP-CLI and for me everything works great. Can you send us some screenshots of your WP Super Cache settings?

@pkaeding

Sure, here are are what seem to be the interesting parts of my WP Super Cache config screens: https://dl.dropbox.com/u/2397175/wpsupercache.pdf. I have the CDN options disabled, so I omitted that screen, but let me know if you want to see that, or anything else that might help.

Thanks!

@getsource
Collaborator

Does it work any better if you change to using mod_rewrite to serve cached files?

@markjaquith

I ran into similar problems with Batcache. Here was my solution:

In wp-config.php, instead of blindly defining WP_CACHE, make sure we're not running on the command line:

if( !defined( 'WP_CACHE' ) && PHP_SAPI !== 'cli' )
    define( 'WP_CACHE', true );
@markjaquith

Two options that I see:

  1. WP-CLI could define WP_CACHE as false
  2. Individuals could use my snippet to not set WP_CACHE when on the command line
@scribu
Owner

WP-CLI could define WP_CACHE as false

I don't see how. Whether it does it before or after wp-config.php is loaded, they'll get a "constant is already defined" error.

Similar problem with WP_DEBUG: #177

@markjaquith
@scribu
Owner

Not the end of the world, but definitely annoying if you have WP_DEBUG on, as any development install should have.

@markjaquith

Ah yeah. So, then I'd recommend option 2: that people add that simple PHP_SAPI !== 'cli' check before defining WP_CACHE. I'm trying to think of a way that WP-CLI could help guide people to that solution...

@scribu
Owner

Another solution would be to move the PHP_SAPI !== 'cli' check into Core, before loading wp-content/advanced-cache.php.

@getsource
Collaborator

The only concern I have about the "let's rely on others or core to set WP_CACHE to false" approach is that part of the primary purpose of wp-cli is the upgrade both plugins and core. In these cases, wp-cli will fail to upgrade, and will never get to the point where it will work without manual intervention.

Perhaps we could provide a flag to force it, with the foreknowledge that it will toss a warning if it fails?
It is still an option to force the define via a config file including PHP, but that's a bit of a significant workaround.

@markjaquith

What about tricking WordPress into thinking that WP-CLI runs are is_admin()? All caching backends I know of bail for that.

@scribu
Owner

That could work.

@scribu
Owner

f28cdcc seems to do the trick.

@scribu scribu merged commit 40c9256 into master
@getsource
Collaborator

Nice!

@scribu scribu referenced this pull request from a commit
@scribu scribu never load advanced-cache.php. see #164 8f3b660
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 4, 2012
  1. @scribu

    pretend we're in /wp-admin/

    scribu authored
This page is out of date. Refresh to see the latest.
Showing with 4 additions and 0 deletions.
  1. +4 −0 src/php/wp-cli/class-wp-cli.php
View
4 src/php/wp-cli/class-wp-cli.php
@@ -268,6 +268,10 @@ static function before_wp_load() {
if ( array( 'core', 'install' ) == self::$arguments ) {
define( 'WP_INSTALLING', true );
}
+
+ // Pretend we're in WP_ADMIN, to side-step full-page caching plugins
+ define( 'WP_ADMIN', true );
+ $_SERVER['PHP_SELF'] = '/wp-admin/index.php';
}
static function after_wp_load() {
Something went wrong with that request. Please try again.