Wednesday, 15 February 2017

Profile WordPress from the Command Line Using Blackfire.io and WP-CLI


Last week I needed a way to use Blackfire.io to profile a POST action in the WordPress administration panel. I thought Blackfire.io would be able to handle POST the way Xdebug does: Generate a different cachegrind file for every PHP invocation; but alas, Blackfire.io currently only does static webpages, command line, or API calls. In theory I could have used “Copy-As-cURL in your Browser” (and believe me I tried) but in practice the WordPress admin is stateless (no $_SESSION), uses check_admin_referer() all over, making whatever POST action I was copying as cURL useless.
My solution was the following hack:
Where `wp` is WP-CLI, `eval-file` loads and executes a PHP file after loading WordPress, `–url=` is the the current site I want to profile on a WordPress multi-site install, and `test.php` is a script containing only the functionality I want to profile.
The profiler data gave some bogus results (Ie. a lot of WP-CLI bootstrapping gets flagged as slow) but at least this was better than nothing.
In the future, it would be great if Blackfire Companion had some sort of option to profile “the next action,” or to “start profiler on submit,” or something
Source: https://managewp.org/articles/14400/profile-wordpress-from-the-command-line-using-blackfire-io-and-wp-cli




source https://williechiu40.wordpress.com/2017/02/15/profile-wordpress-from-the-command-line-using-blackfire-io-and-wp-cli/

No comments:

Post a Comment