Comments (7)
It would be pretty sweet if I could do:
As it turns out, you can!
- Create a PHP file to execute
$ cat media-regenerate.php
<?php
WP_CLI::runcommand( 'media regenerate --yes', array( 'launch' => false ) );
- Profile PHP file execution
$ wp profile eval-file media-regenerate.php
Found 1 image to regenerate.
1/1 Regenerated thumbnails for "download" (ID 7).
Success: Regenerated 1 of 1 images.
+---------+------------+-------------+-------------+------------+--------------+--------------+---------------+
| time | query_time | query_count | cache_ratio | cache_hits | cache_misses | request_time | request_count |
+---------+------------+-------------+-------------+------------+--------------+--------------+---------------+
| 0.9374s | 0.0284s | 6 | 88.68% | 47 | 6 | 0s | 0 |
+---------+------------+-------------+-------------+------------+--------------+--------------+---------------+
from profile-command.
I don't think the above result is correct. It doesn't show any internal profiling data (like the query count and time), it seems to only do what a basic time
would do: diff the start and end times.
from profile-command.
Oops. I forgot to keep the current process.
I've updated my comment to include:
WP_CLI::runcommand( 'media regenerate --yes', array( 'launch' => false ) );
from profile-command.
Hehe, this ties neatly into wp-cli/wp-cli#3890 :
It shouldn't be as easy to have completely different behavior (resulting in a bug) just because you forgot an obscure array argument.
from profile-command.
It shouldn't be as easy to have completely different behavior (resulting in a bug) just because you forgot an obscure array argument.
The behavioral difference occurs because WP_CLI::runcommand()
's default behavior is to launch a new process. In order to track queries, etc., wp profile
needs access to the $wpdb
variable of the process, which it doesn't have when a new process is launched.
Technically speaking, the original result was correct, because no queries occurred in the current process.
Could you explain how wp-cli/wp-cli#3890 would've caught this? I think it's reasonable to have default behavior for methods, and optional arguments to change the behavior.
from profile-command.
I think it should be obvious from either the method or the arguments what the expected behavior is. So, in the above example, a very simple disambiguation would be to either require the 'launch'
argument, or to have different methods for these very different behaviors, like run_command_in_same_process
and run_command_in_new_process
(I know, not the catchiest method names).
The point is that the intent should be clear and unambiguous. Providing default fallback values is nice for situations where it's mostly just about convenience. But in this particular case, runcommand
is actually a facade to an entire category of methods, and they are chosen based on array arguments, which are neither validated nor checked in any other way. The default fallback values actually choose which specific type of functionality to run whenever you didn't provide overrides.
from profile-command.
I've left a comment on the linked issue.
from profile-command.
Related Issues (20)
- Skipping Fatal errors possible? HOT 2
- Broken docs for --format argument
- Move command over to new v2 structure
- Invalid field: callback_count with --format=json and --fields not specified HOT 1
- Profile command returns homepage source code HOT 15
- A Trailing Slash Gets Added To URL Causing A Redirect HOT 1
- Adopt and enforce new `WP_CLI_CS` standard
- Warning: count(): Parameter must be an array or an object that implements Countable inc/class-logger.php on line 65 HOT 6
- Warning during installation: PHP Notice: Trying to access array offset on value of type null HOT 1
- Installation error: Your requirements could not be resolved to an installable set of packages HOT 3
- PHP Fatal error: Allowed memory size on install package HOT 1
- broken link on readme HOT 1
- Getting "fatal: No such remote 'composer'" while installing this command HOT 4
- Unexpected End Of File HOT 1
- SSL certificate problem on install. HOT 7
- Description missing for "wp profile" Command HOT 1
- Warnings on PHP 8.3
- SQLite Compatibility
- Dynamic property warnings in `Logger` class on PHP 8.2 HOT 6
- PHP 7 error reported when profiling intermediate hook with LSPHP 8.1.24 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from profile-command.