• Stars
    star
    253
  • Rank 155,839 (Top 4 %)
  • Language
    PHP
  • License
    MIT License
  • Created almost 8 years ago
  • Updated about 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Quickly identify what's slow with WordPress

wp-cli/profile-command

Quickly identify what's slow with WordPress.

Testing

Quick links: Overview | Using | Installing | Contributing

Overview

wp profile monitors key performance indicators of the WordPress execution process to help you quickly identify points of slowness.

Save hours diagnosing slow WordPress sites. Because you can easily run it on any server that supports WP-CLI, wp profile compliments Xdebug and New Relic by pointing you in the right direction for further debugging. Because it runs on the command line, using wp profile means you don't have to install a plugin and deal with the painful dashboard of a slow WordPress site. And, because it's a WP-CLI command, wp profile makes it easy to perfom hard tasks (e.g. profiling a WP REST API response).

Identify why WordPress is slow in just a few steps with wp profile.

Using

This package implements the following commands:

wp profile stage

Profile each stage of the WordPress load process (bootstrap, main_query, template).

wp profile stage [<stage>] [--all] [--spotlight] [--url=<url>] [--fields=<fields>] [--format=<format>] [--order=<order>] [--orderby=<orderby>]

When WordPress handles a request from a browser, itโ€™s essentially executing as one long PHP script. wp profile stage breaks the script into three stages:

  • bootstrap is where WordPress is setting itself up, loading plugins and the main theme, and firing the init hook.
  • main_query is how WordPress transforms the request (e.g. /2016/10/21/moms-birthday/) into the primary WP_Query.
  • template is where WordPress determines which theme template to render based on the main query, and renders it.
# `wp profile stage` gives an overview of each stage.
$ wp profile stage --fields=stage,time,cache_ratio
+------------+---------+-------------+
| stage      | time    | cache_ratio |
+------------+---------+-------------+
| bootstrap  | 0.7994s | 93.21%      |
| main_query | 0.0123s | 94.29%      |
| template   | 0.792s  | 91.23%      |
+------------+---------+-------------+
| total (3)  | 1.6037s | 92.91%      |
+------------+---------+-------------+

# Then, dive into hooks for each stage with `wp profile stage <stage>`
$ wp profile stage bootstrap --fields=hook,time,cache_ratio --spotlight
+--------------------------+---------+-------------+
| hook                     | time    | cache_ratio |
+--------------------------+---------+-------------+
| muplugins_loaded:before  | 0.2335s | 40%         |
| muplugins_loaded         | 0.0007s | 50%         |
| plugins_loaded:before    | 0.2792s | 77.63%      |
| plugins_loaded           | 0.1502s | 100%        |
| after_setup_theme:before | 0.068s  | 100%        |
| init                     | 0.2643s | 96.88%      |
| wp_loaded:after          | 0.0377s |             |
+--------------------------+---------+-------------+
| total (7)                | 1.0335s | 77.42%      |
+--------------------------+---------+-------------+

OPTIONS

[<stage>]
	Drill down into a specific stage.

[--all]
	Expand upon all stages.

[--spotlight]
	Filter out logs with zero-ish values from the set.

[--url=<url>]
	Execute a request against a specified URL. Defaults to the home URL.

[--fields=<fields>]
	Limit the output to specific fields. Default is all fields.

[--format=<format>]
	Render output in a particular format.
	---
	default: table
	options:
	  - table
	  - json
	  - yaml
	  - csv
	---

[--order=<order>]
	Ascending or Descending order.
	---
	default: ASC
	options:
	  - ASC
	  - DESC
	---

[--orderby=<orderby>]
	Order by fields.

wp profile hook

Profile key metrics for WordPress hooks (actions and filters).

wp profile hook [<hook>] [--all] [--spotlight] [--url=<url>] [--fields=<fields>] [--format=<format>] [--order=<order>] [--orderby=<orderby>]

In order to profile callbacks on a specific hook, the action or filter will need to execute during the course of the request.

OPTIONS

[<hook>]
	Drill into key metrics of callbacks on a specific WordPress hook.

[--all]
	Profile callbacks for all WordPress hooks.

[--spotlight]
	Filter out logs with zero-ish values from the set.

[--url=<url>]
	Execute a request against a specified URL. Defaults to the home URL.

[--fields=<fields>]
	Display one or more fields.

[--format=<format>]
	Render output in a particular format.
	---
	default: table
	options:
	  - table
	  - json
	  - yaml
	  - csv
	---

[--order=<order>]
	Ascending or Descending order.
	---
	default: ASC
	options:
	  - ASC
	  - DESC
	---

[--orderby=<orderby>]
	Order by fields.

wp profile eval

Profile arbitrary code execution.

wp profile eval <php-code> [--hook[=<hook>]] [--fields=<fields>] [--format=<format>] [--order=<order>] [--orderby=<orderby>]

Code execution happens after WordPress has loaded entirely, which means you can use any utilities defined in WordPress, active plugins, or the current theme.

OPTIONS

<php-code>
	The code to execute, as a string.

[--hook[=<hook>]]
	Focus on key metrics for all hooks, or callbacks on a specific hook.

[--fields=<fields>]
	Display one or more fields.

[--format=<format>]
	Render output in a particular format.
	---
	default: table
	options:
	  - table
	  - json
	  - yaml
	  - csv
	---

[--order=<order>]
	Ascending or Descending order.
	---
	default: ASC
	options:
	  - ASC
	  - DESC
	---

[--orderby=<orderby>]
	Order by fields.

wp profile eval-file

Profile execution of an arbitrary file.

wp profile eval-file <file> [--hook[=<hook>]] [--fields=<fields>] [--format=<format>] [--order=<order>] [--orderby=<orderby>]

File execution happens after WordPress has loaded entirely, which means you can use any utilities defined in WordPress, active plugins, or the current theme.

OPTIONS

<file>
	The path to the PHP file to execute and profile.

[--hook[=<hook>]]
	Focus on key metrics for all hooks, or callbacks on a specific hook.

[--fields=<fields>]
	Display one or more fields.

[--format=<format>]
	Render output in a particular format.
	---
	default: table
	options:
	  - table
	  - json
	  - yaml
	  - csv
	---

[--order=<order>]
	Ascending or Descending order.
	---
	default: ASC
	options:
	  - ASC
	  - DESC
	---

[--orderby=<orderby>]
	Order by fields.

Installing

Installing this package requires WP-CLI v2.5 or greater. Update to the latest stable release with wp cli update.

Once you've done so, you can install the latest stable version of this package with:

wp package install wp-cli/profile-command:@stable

To install the latest development version of this package, use the following command instead:

wp package install wp-cli/profile-command:dev-master

Contributing

We appreciate you taking the initiative to contribute to this project.

Contributing isnโ€™t limited to just code. We encourage you to contribute in the way that best fits your abilities, by writing tutorials, giving a demo at your local meetup, helping other users with their support questions, or revising our documentation.

For a more thorough introduction, check out WP-CLI's guide to contributing. This package follows those policy and guidelines.

Reporting a bug

Think youโ€™ve found a bug? Weโ€™d love for you to help us get it fixed.

Before you create a new issue, you should search existing issues to see if thereโ€™s an existing resolution to it, or if itโ€™s already been fixed in a newer version.

Once youโ€™ve done a bit of searching and discovered there isnโ€™t an open or fixed issue for your bug, please create a new issue. Include as much detail as you can, and clear steps to reproduce if possible. For more guidance, review our bug report documentation.

Creating a pull request

Want to contribute a new feature? Please first open a new issue to discuss whether the feature is a good fit for the project.

Once you've decided to commit the time to seeing your pull request through, please follow our guidelines for creating a pull request to make sure it's a pleasant experience. See "Setting up" for details specific to working on this package locally.

This README.md is generated dynamically from the project's codebase using wp scaffold package-readme (doc). To suggest changes, please submit a pull request against the corresponding part of the codebase.

More Repositories

1

wp-cli

โš™๏ธ WP-CLI framework
PHP
4,808
star
2

php-cli-tools

A collection of tools to help with PHP command line utilities
PHP
667
star
3

handbook

๐Ÿ“– Complete documentation for WP-CLI
PHP
178
star
4

scaffold-command

Generates code for post types, taxonomies, blocks, plugins, child themes, etc.
Gherkin
164
star
5

restful

Unlocking the potential of the WP REST API at the command line
PHP
146
star
6

doctor-command

Diagnose problems within WordPress by running a series of checks for symptoms
Gherkin
134
star
7

sample-plugin

Example plugin, generated using `wp scaffold plugin sample-plugin`
Shell
101
star
8

i18n-command

Provides internationalization tools for WordPress projects.
Gherkin
93
star
9

entity-command

Manage WordPress comments, menus, options, posts, sites, terms, and users.
PHP
92
star
10

wp-cli-bundle

๐Ÿ“ฆ WP-CLI package that bundles the framework with a set of common commands
Gherkin
81
star
11

extension-command

Manages plugins and themes, including installs, activations, and updates.
PHP
79
star
12

wp-config-transformer

Programmatically edit a wp-config.php file
PHP
76
star
13

scaffold-package-command

Scaffolds WP-CLI commands with functional tests, full README.md, and more.
Gherkin
68
star
14

db-command

Performs basic database operations using credentials stored in wp-config.php.
PHP
68
star
15

server-command

Launches PHP's built-in web server for a specific WordPress installation.
PHP
68
star
16

search-replace-command

Searches/replaces strings in the database.
Gherkin
58
star
17

wp-super-cache-cli

A CLI interface for the WP Super Cache plugin
PHP
56
star
18

core-command

Downloads, installs, updates, and manages a WordPress installation.
Gherkin
48
star
19

dist-archive-command

Create a distribution .zip or .tar.gz based on a plugin or theme's .distignore file
Gherkin
42
star
20

media-command

Imports files as attachments, regenerates thumbnails, or lists registered image sizes.
Gherkin
42
star
21

ideas

๐Ÿ’ก Ideas and feature requests are collected here
39
star
22

wp-cli-dev

๐Ÿ›  WP-CLI development environment that allows for easy development across all packages
PHP
36
star
23

builds

Phar, Debian, and RPM builds of WP-CLI
35
star
24

wp-cli-tests

WP-CLI testing framework
PHP
32
star
25

config-command

Generates and reads the wp-config.php file.
Gherkin
32
star
26

package-index

A list of packages containing WP-CLI commands
Twig
31
star
27

checksum-command

Verifies file integrity by comparing to published checksums.
PHP
31
star
28

cron-command

Tests, runs, and deletes WP-Cron events; manages WP-Cron schedules.
PHP
30
star
29

wp-cli.github.com

wp-cli.org website
CSS
24
star
30

shell-command

Opens an interactive PHP console for running and testing PHP code.
PHP
20
star
31

import-command

Imports content from a given WXR file.
PHP
20
star
32

rewrite-command

Lists or flushes the site's rewrite rules, updates the permalink structure.
PHP
20
star
33

package-command

Lists, installs, and removes WP-CLI packages.
PHP
17
star
34

google-sitemap-generator-cli

A CLI interface for the Google Sitemap Generator plugin
Gherkin
17
star
35

find-command

Find WordPress installations on the filesystem
PHP
14
star
36

admin-command

Open /wp-admin/ in a browser
PHP
14
star
37

cache-command

Manages object and transient caches.
PHP
14
star
38

language-command

Installs, activates, and manages language packs.
PHP
12
star
39

dash-docset-generator

WP-CLI Dash docset generator
PHP
12
star
40

export-command

Exports WordPress content to a WXR file.
PHP
12
star
41

maintenance-mode-command

Activates, deactivates or checks the status of the maintenance mode of a site.
PHP
9
star
42

super-admin-command

Lists, adds, or removes super admin users on a multisite installation.
Gherkin
9
star
43

eval-command

Executes arbitrary PHP code or files.
Gherkin
8
star
44

embed-command

Inspects oEmbed providers, clears embed cache, and more.
Gherkin
7
star
45

.github

๐ŸŒ Centralized community health files for all repositories
6
star
46

widget-command

Adds, moves, and removes widgets; lists sidebars.
PHP
5
star
47

role-command

Adds, removes, lists, and resets roles and capabilities.
PHP
5
star
48

automated-tests

Runs the entire test suite on a regular basis
Shell
4
star
49

autoload-splitter

PHP
3
star
50

wp-cli-shim

This repository provides easy way to install WP-CLI without the risk of conflicting dependencies.
2
star
51

dashboard

Dashboard for WP-CLI contributors
HTML
1
star
52

wp-cli-roadmap

Roadmap planning for WP-CLI
1
star
53

rpm-build

Builds a RPM of the latest stable WP-CLI release
1
star
54

deb-build

1
star