Method for clearing object caches which are not available on the command line #283

Closed
markjaquith opened this Issue Feb 1, 2013 · 14 comments

Projects

None yet

7 participants

@markjaquith
Contributor

I use my APC Object Cache plugin on a lot of single-server installs, and on my locally hosted dev versions thereof. But APC isn't available when PHP runs on the command line. So if I activate a plugin with WP-CLI, then check it through a web server, it won't be activated until I restart PHP or otherwise flush the APC cache.

I'd like to think up a way that this could be done from the command line, so I can run WP-CLI commands, flush out the cache, and then go on my way. As we don't have access to APC, it'll have to involve some sort of command-line-to-WordPress-running-on-a-web-server communication.

Ideas:

  1. Trigger an HTTP request that the WordPress install will respond to.
  2. Update a flag somewhere in the database, the checking of which on the web server version will somehow skip the cache, and then trigger the flush. Perhaps a direct query on an option.

Any other ideas?

@scribu
Member
scribu commented Feb 1, 2013

What about the apc.enable-cli directive?

@markjaquith
Contributor

My understanding was that you don't get a persistent cache on the command line. Emphasis added:

Mostly for testing and debugging. Setting this enables APC for the CLI version of PHP. Under normal circumstances, it is not ideal to create, populate and destroy the APC cache on every CLI request, but for various test scenarios it is useful to be able to enable APC for the CLI version of PHP easily.

@joehoyle
joehoyle commented Feb 8, 2013

I have run into this issue (though with phpunit, but I think the same applies). When using APC via CLI, you don't get access to the same persistant cache. I ended up working around it by switching to memcache unfortunately.

Only other way I know how to clear the apc cache is to restart FPM / Apache or whatever server you may be using, which may be overkill.

@scribu
Member
scribu commented Apr 8, 2013

Closing, since I'm not keen on the HTTP-based solution.

LE: Still, if someone ends up implementing it as a plugin or otherwise, do share.

@scribu scribu closed this Apr 8, 2013
@Rarst
Contributor
Rarst commented Mar 20, 2014

Hit this issue as linked above. I don't see easy solution so far.

Maybe for a start wp-cli shouldn't perform related commands in environment they are known to fail? wp cache type seems to detect "APC" as object cache, maybe it should be flag to lock out commands affected by the issue for now?

@scribu
Member
scribu commented Mar 20, 2014

Yeah, throwing an error when APC is detected was what I had in mind.

@scribu scribu reopened this Mar 20, 2014
@scribu scribu added this to the next milestone Mar 20, 2014
@scribu
Member
scribu commented Mar 27, 2014

maybe it should be flag to lock out commands affected by the issue for now?

Any command that alters database rows is affected by this, so I went with a more straightforward solution, for now: always abort.

@scribu scribu removed the bug label Mar 27, 2014
@scribu scribu removed this from the next milestone Mar 27, 2014
@zamoose
zamoose commented May 23, 2014

So here's the problem: there are two ways of enabling APC -- for the web runtime and the CLI. They're enabled separately (see http://www.php.net/manual/en/apc.configuration.php#ini.apc.enable-cli for enabling for CLI). I think this is a bad check and it's killing our ability to use CLI on servers with APC enabled. This needs a different approach.

@scribu
Member
scribu commented May 23, 2014

An alternative approach would be to output a prompt:

Warning: Running WP-CLI while the APC object cache is activated can result in cache corruption. Continue? [y/n]

Thus, we leave it up to the user to make the call.

@zamoose
zamoose commented May 23, 2014

That, or dump with an error but add a flag similar to --allow-root.

--allow-apc?

On Fri, May 23, 2014 at 10:20 AM, Cristi Burcă notifications@github.comwrote:

An alternative approach would be to output a prompt:

Warning: Running WP-CLI while the APC object cache is activated can result in cache corruption. Continue? [y/n]

Thus, we leave it up to the user to make the call.


Reply to this email directly or view it on GitHubhttps://github.com/wp-cli/wp-cli/issues/283#issuecomment-44014505
.

-Doug

@zamoose
zamoose commented Sep 3, 2014

Any further thoughts on this one?

@danielbachhuber
Member

I'd be open to seeing a pull request that switches to to a warning / prompt.

@szepeviktor
Member

@markjaquith Are you interested in a wp-cli package from porting this class?

@danielbachhuber
Member

Going with a warning like this:

salty-wordpress ➜  wordpress-test.dev  wp --require=cache.php option get home
Warning: Running WP-CLI while the APC object cache is activated can result in cache corruption.
Given the consequences, do you wish to continue? [y/n]
@danielbachhuber danielbachhuber added this to the 0.21.0 milestone Sep 20, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment