-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Persistent WP instance to speed up WP-CLI #179
Comments
The idea is generally interesting. However, we need to be aware of some limitations regarding such an approach. These mostly come from the fact that this goes against the design principles and architecture of WordPress itself. WordPress is built in such a way that each request is meant to start a new process from scratch. This means that there are no precautions being taken within the active WP process to deal with multiple changes that depend on each other's side-effects. As an example, depending on what you're trying to do, you'd need to manually invalidate/reset some caches between one WP-CLI call and the next to make sure that the second one actually sees the changes the first one did. How would you consider solving against this? Would it be okay to put the onus on the user and expect them to do a |
The constants make things complicated... Is there any way to pre-compile the code prior to capturing system state, then fork for each command? My idea breaks of course if you do something like install a plugin or upgrade wordpress, etc... Possibly the orchestrator would somehow know to "reload" when that happens. I realize this is all a stretch. But maybe it will lend some ideas. |
A lesser proposal to this idea might be to do something like this. Would it solve the problem you're trying to solve @kkmuffme? echo 'set options blogname "my title"' > commands.txt
echo 'set options blogdescription "my description"' >> commands.txt
echo 'core update' >> commands.txt
wp-cli --json runcommands << commands.txt Possibly this command would come with a caveat emptor that it may have unexpected side effects. In my above example, I would be required to know that messing with blogname/description will not have side effects on each other and that the update would be fine following the first 2. If we wanted to get fancy, maybe we'd add a The JSON result might provide an array of responses from each command. |
Yes. As this goes far beyond the use case of an average WordPress user. For most use cases, there's no special requirement - and in fact in some cases, we can automatically end the instance and create a new one internally - e.g. on plugin activation, to fix this issue automatically. @toddr unfortunately I can't do this, since all the "if" code won't work then - this works fine for updating/deleting options, but won't work when I have to check if a plugin is active,... making it too restrictive. The simplest version of it would be to start a WP request and put a while/sleep after some specific hook.
Basically making a WP request infinite (or until CLI timeout is reached or it's closed). |
It almost sounds like you want to create your own CLI plugin that could then do complex things that you need and could handle the conditionals? |
Cool. I've moved my idea to #180 |
Not really, since this is a general issue with WP CLI - unless you use WP CLI to update a single option or do a single operation (which is rather unlikely) you will have this issue |
I realized another thing that needs consideration here: |
Depending on how this is implemented, the security is already handled by default Linux file permissions. e.g. the linked serverfault solution using the pipe, will be created with default umask permissions of the current user/directory. |
Perhaps I missed it, but I haven't seen anyone address @schlessera's comments about how this goes completely against the architecture of Wordpress. A few months ago I spent the better part of a week exploring how to run Wordpress itself (not wpcli) in one of the various async php servers (swoole, roadrunner, reactphp, frankenphp, etc...) and the conclusion is fundamentally that it would require a complete reworking of Wordpress Core and probably most plugins as, for example, they all create and use global variables that would change/interfere with each request. So, if something were ever to be attempted here, it would be better/necessary to instead do it for WP Core itself. I don't see that ever happening... |
That's not an issue for most WP CLI commands since all the globals used in WP are for states of a specific page only, but WP CLI is stateless in general, just like e.g. wp-cron.php is. |
Ah ok, I guess I need more experience with wp cli! I only stumbled upon this while starting my research into making a package for it. |
Feature Request
Describe your use case and the problem you are facing
Since WP CLI always initiates a new PHP CLI/WP process, you have the WP overhead for every command, which makes it the slowest part of many pipelines.
Additionally having to specify common commands every time is a chore to write, e.g.
--skip-plugins --skip-themes
to make it faster.Describe the solution you'd like
Since PHP CLI has no/long timeouts, it would make sense to give the option to "launch" a WP instance once and then reuse it.
It would be faster when we launch a WP instance and then just read a file in a while loop like https://serverfault.com/a/1088115 to execute the commands passed subsequently.
This could be an optional thing with
--persist=my-instance
for example.Since the WP overhead is between 150-350ms on a barebones WP install and much higher on slow servers or with many plugins, this would save tons of runtime.
The text was updated successfully, but these errors were encountered: