WP-CLI como herramienta de análisis

Última actualización: 20 de diciembre de 2020

Si aún no tienes WP-CLI, instálalo en tu servidor. Una vez lo tengas, puedes ampliar su funcionalidad.

WP-CLI profile

WP-CLI profile hace un análisis de varios indicadores de la ejecución en una instalación de WordPress de forma que puedas detectar puntos lentos en su funcionamiento.

Lo primero será instalarlo si no lo tienes ya.

wp package install wp-cli/profile-command --allow-root

Una vez lo tengamos instalado, podemos ir a la carpeta donde tengamos el WordPress a analizar.

cd /home/example.com/public_html/

Cuando estemos en la carpeta donde tenemos nuestro WordPress, podremos realizar una serie de consultas.

La primera de ellas es la del «bootstrap», que analizará la instalación base de WordPress, cargando el propio WordPress, los plugins, themes y el inicio.

wp profile stage bootstrap --all --allow-root

Esto nos devolverá una tabla similar a la siguiente:

+--------------------------+----------------+---------+------------+-------------+-------------+------------+--------------+--------------+---------------+
| hook                     | callback_count | time    | query_time | query_count | cache_ratio | cache_hits | cache_misses | request_time | request_count |
+--------------------------+----------------+---------+------------+-------------+-------------+------------+--------------+--------------+---------------+
| muplugins_loaded:before  |                | 0.1316s | 0.0006s    | 1           | 25%         | 1          | 3            | 0s           | 0             |
| muplugins_loaded         | 2              | 0.0002s | 0s         | 0           | 50%         | 1          | 1            | 0s           | 0             |
| plugins_loaded:before    |                | 0.0161s | 0.0006s    | 2           | 54.17%      | 13         | 11           | 0s           | 0             |
| plugins_loaded           | 5              | 0.004s  | 0s         | 0           |             | 0          | 0            | 0s           | 0             |
| setup_theme:before       |                | 0.0002s | 0s         | 0           | 100%        | 4          | 0            | 0s           | 0             |
| setup_theme              | 2              | 0.0004s | 0s         | 0           |             | 0          | 0            | 0s           | 0             |
| after_setup_theme:before |                | 0.0072s | 0s         | 0           | 100%        | 89         | 0            | 0s           | 0             |
| after_setup_theme        | 2              | 0.0008s | 0s         | 0           | 100%        | 6          | 0            | 0s           | 0             |
| init:before              |                | 0.0024s | 0s         | 0           | 100%        | 2          | 0            | 0s           | 0             |
| init                     | 30             | 0.0197s | 0.0006s    | 2           | 98.97%      | 192        | 2            | 0s           | 0             |
| wp_loaded:before         |                | 0s      | 0s         | 0           |             | 0          | 0            | 0s           | 0             |
| wp_loaded                | 1              | 0s      | 0s         | 0           |             | 0          | 0            | 0s           | 0             |
| parse_request:before     |                | 0.0242s | 0s         | 0           | 100%        | 4          | 0            | 0s           | 0             |
| parse_request            | 1              | 0s      | 0s         | 0           |             | 0          | 0            | 0s           | 0             |
| send_headers:before      |                | 0.0001s | 0s         | 0           | 100%        | 4          | 0            | 0s           | 0             |
| send_headers             | 0              | 0s      | 0s         | 0           |             | 0          | 0            | 0s           | 0             |
| pre_get_posts:before     |                | 0.0002s | 0s         | 0           | 100%        | 2          | 0            | 0s           | 0             |
| pre_get_posts            | 1              | 0s      | 0s         | 0           |             | 0          | 0            | 0s           | 0             |
| the_posts:before         |                | 0.001s  | 0.0005s    | 1           | 100%        | 6          | 0            | 0s           | 0             |
| the_posts                | 2              | 0s      | 0s         | 0           |             | 0          | 0            | 0s           | 0             |
| wp:before                |                | 0s      | 0s         | 0           |             | 0          | 0            | 0s           | 0             |
| wp                       | 0              | 0s      | 0s         | 0           |             | 0          | 0            | 0s           | 0             |
| template_redirect:before |                | 0.0002s | 0s         | 0           |             | 0          | 0            | 0s           | 0             |
| template_redirect        | 7              | 0.0006s | 0s         | 0           | 100%        | 14         | 0            | 0s           | 0             |
| template_include:before  |                | 0.0001s | 0s         | 0           | 100%        | 2          | 0            | 0s           | 0             |
| template_include         | 0              | 0s      | 0s         | 0           |             | 0          | 0            | 0s           | 0             |
| wp_head:before           |                | 0.0008s | 0s         | 0           | 100%        | 10         | 0            | 0s           | 0             |
| wp_head                  | 25             | 0.0037s | 0s         | 0           | 95.37%      | 103        | 5            | 0s           | 0             |
| loop_start:before        |                | 0.0013s | 0s         | 0           | 100%        | 64         | 0            | 0s           | 0             |
| loop_start               | 0              | 0s      | 0s         | 0           |             | 0          | 0            | 0s           | 0             |
| loop_end:before          |                | 0.0054s | 0.0005s    | 2           | 97.39%      | 112        | 3            | 0s           | 0             |
| loop_end                 | 0              | 0s      | 0s         | 0           |             | 0          | 0            | 0s           | 0             |
| wp_footer:before         |                | 0.0046s | 0.0012s    | 4           | 94.44%      | 68         | 4            | 0s           | 0             |
| wp_footer                | 5              | 0.0004s | 0s         | 0           | 100%        | 4          | 0            | 0s           | 0             |
| wp_footer:after          |                | 0s      | 0s         | 0           |             | 0          | 0            | 0s           | 0             |
+--------------------------+----------------+---------+------------+-------------+-------------+------------+--------------+--------------+---------------+
| total (35)               | 83             | 0.2255s | 0.0041s    | 12          | 90.77%      | 701        | 29           | 0s           | 0             |
+--------------------------+----------------+---------+------------+-------------+-------------+------------+--------------+--------------+---------------+

La segunda prueba es la de hacer una consulta al «loop» para traer información de una entrada o contenido.

wp profile stage main_query --all --allow-root

Esto nos devolverá una tabla similar a la siguiente:

+--------------------------+----------------+---------+------------+-------------+-------------+------------+--------------+--------------+---------------+
| hook                     | callback_count | time    | query_time | query_count | cache_ratio | cache_hits | cache_misses | request_time | request_count |
+--------------------------+----------------+---------+------------+-------------+-------------+------------+--------------+--------------+---------------+
| muplugins_loaded:before  |                | 0.1427s | 0.0005s    | 1           | 25%         | 1          | 3            | 0s           | 0             |
| muplugins_loaded         | 2              | 0.0002s | 0s         | 0           | 50%         | 1          | 1            | 0s           | 0             |
| plugins_loaded:before    |                | 0.0163s | 0.0006s    | 2           | 54.17%      | 13         | 11           | 0s           | 0             |
| plugins_loaded           | 5              | 0.0043s | 0s         | 0           |             | 0          | 0            | 0s           | 0             |
| setup_theme:before       |                | 0.0003s | 0s         | 0           | 100%        | 4          | 0            | 0s           | 0             |
| setup_theme              | 2              | 0.0005s | 0s         | 0           |             | 0          | 0            | 0s           | 0             |
| after_setup_theme:before |                | 0.0079s | 0s         | 0           | 100%        | 89         | 0            | 0s           | 0             |
| after_setup_theme        | 2              | 0.0008s | 0s         | 0           | 100%        | 6          | 0            | 0s           | 0             |
| init:before              |                | 0.0026s | 0s         | 0           | 100%        | 2          | 0            | 0s           | 0             |
| init                     | 30             | 0.0222s | 0.0006s    | 2           | 98.97%      | 192        | 2            | 0s           | 0             |
| wp_loaded:before         |                | 0s      | 0s         | 0           |             | 0          | 0            | 0s           | 0             |
| wp_loaded                | 1              | 0s      | 0s         | 0           |             | 0          | 0            | 0s           | 0             |
| parse_request:before     |                | 0.0255s | 0s         | 0           | 100%        | 4          | 0            | 0s           | 0             |
| parse_request            | 1              | 0s      | 0s         | 0           |             | 0          | 0            | 0s           | 0             |
| send_headers:before      |                | 0.0001s | 0s         | 0           | 100%        | 4          | 0            | 0s           | 0             |
| send_headers             | 0              | 0s      | 0s         | 0           |             | 0          | 0            | 0s           | 0             |
| pre_get_posts:before     |                | 0.0001s | 0s         | 0           | 100%        | 2          | 0            | 0s           | 0             |
| pre_get_posts            | 1              | 0s      | 0s         | 0           |             | 0          | 0            | 0s           | 0             |
| the_posts:before         |                | 0.0007s | 0.0002s    | 1           | 100%        | 6          | 0            | 0s           | 0             |
| the_posts                | 2              | 0s      | 0s         | 0           |             | 0          | 0            | 0s           | 0             |
| wp:before                |                | 0s      | 0s         | 0           |             | 0          | 0            | 0s           | 0             |
| wp                       | 0              | 0s      | 0s         | 0           |             | 0          | 0            | 0s           | 0             |
| template_redirect:before |                | 0.0003s | 0s         | 0           |             | 0          | 0            | 0s           | 0             |
| template_redirect        | 7              | 0.0009s | 0s         | 0           | 100%        | 14         | 0            | 0s           | 0             |
| template_include:before  |                | 0.0002s | 0s         | 0           | 100%        | 2          | 0            | 0s           | 0             |
| template_include         | 0              | 0s      | 0s         | 0           |             | 0          | 0            | 0s           | 0             |
| wp_head:before           |                | 0.0009s | 0s         | 0           | 100%        | 10         | 0            | 0s           | 0             |
| wp_head                  | 25             | 0.0036s | 0s         | 0           | 95.37%      | 103        | 5            | 0s           | 0             |
| loop_start:before        |                | 0.0014s | 0s         | 0           | 100%        | 64         | 0            | 0s           | 0             |
| loop_start               | 0              | 0s      | 0s         | 0           |             | 0          | 0            | 0s           | 0             |
| loop_end:before          |                | 0.0053s | 0.0005s    | 2           | 97.39%      | 112        | 3            | 0s           | 0             |
| loop_end                 | 0              | 0s      | 0s         | 0           |             | 0          | 0            | 0s           | 0             |
| wp_footer:before         |                | 0.0044s | 0.0009s    | 4           | 94.44%      | 68         | 4            | 0s           | 0             |
| wp_footer                | 5              | 0.0004s | 0s         | 0           | 100%        | 4          | 0            | 0s           | 0             |
| wp_footer:after          |                | 0s      | 0s         | 0           |             | 0          | 0            | 0s           | 0             |
+--------------------------+----------------+---------+------------+-------------+-------------+------------+--------------+--------------+---------------+
| total (35)               | 83             | 0.2418s | 0.0034s    | 12          | 90.77%      | 701        | 29           | 0s           | 0             |
+--------------------------+----------------+---------+------------+-------------+-------------+------------+--------------+--------------+---------------+

La tercera y última prueba es la de hacer una consulta al «template», que cargaría el núcleo y la información para presentarla en el frontal.

wp profile stage template --all --allow-root

Esto nos devolverá una tabla similar a la siguiente:

+--------------------------+----------------+---------+------------+-------------+-------------+------------+--------------+--------------+---------------+
| hook                     | callback_count | time    | query_time | query_count | cache_ratio | cache_hits | cache_misses | request_time | request_count |
+--------------------------+----------------+---------+------------+-------------+-------------+------------+--------------+--------------+---------------+
| muplugins_loaded:before  |                | 0.1338s | 0.0006s    | 1           | 25%         | 1          | 3            | 0s           | 0             |
| muplugins_loaded         | 2              | 0.0002s | 0s         | 0           | 50%         | 1          | 1            | 0s           | 0             |
| plugins_loaded:before    |                | 0.0152s | 0.0006s    | 2           | 54.17%      | 13         | 11           | 0s           | 0             |
| plugins_loaded           | 5              | 0.0038s | 0s         | 0           |             | 0          | 0            | 0s           | 0             |
| setup_theme:before       |                | 0.0002s | 0s         | 0           | 100%        | 4          | 0            | 0s           | 0             |
| setup_theme              | 2              | 0.0004s | 0s         | 0           |             | 0          | 0            | 0s           | 0             |
| after_setup_theme:before |                | 0.0068s | 0s         | 0           | 100%        | 89         | 0            | 0s           | 0             |
| after_setup_theme        | 2              | 0.0008s | 0s         | 0           | 100%        | 6          | 0            | 0s           | 0             |
| init:before              |                | 0.0023s | 0s         | 0           | 100%        | 2          | 0            | 0s           | 0             |
| init                     | 30             | 0.0193s | 0.0008s    | 2           | 98.97%      | 192        | 2            | 0s           | 0             |
| wp_loaded:before         |                | 0s      | 0s         | 0           |             | 0          | 0            | 0s           | 0             |
| wp_loaded                | 1              | 0s      | 0s         | 0           |             | 0          | 0            | 0s           | 0             |
| parse_request:before     |                | 0.0231s | 0s         | 0           | 100%        | 4          | 0            | 0s           | 0             |
| parse_request            | 1              | 0s      | 0s         | 0           |             | 0          | 0            | 0s           | 0             |
| send_headers:before      |                | 0.0001s | 0s         | 0           | 100%        | 4          | 0            | 0s           | 0             |
| send_headers             | 0              | 0s      | 0s         | 0           |             | 0          | 0            | 0s           | 0             |
| pre_get_posts:before     |                | 0.0001s | 0s         | 0           | 100%        | 2          | 0            | 0s           | 0             |
| pre_get_posts            | 1              | 0s      | 0s         | 0           |             | 0          | 0            | 0s           | 0             |
| the_posts:before         |                | 0.0008s | 0.0003s    | 1           | 100%        | 6          | 0            | 0s           | 0             |
| the_posts                | 2              | 0s      | 0s         | 0           |             | 0          | 0            | 0s           | 0             |
| wp:before                |                | 0s      | 0s         | 0           |             | 0          | 0            | 0s           | 0             |
| wp                       | 0              | 0s      | 0s         | 0           |             | 0          | 0            | 0s           | 0             |
| template_redirect:before |                | 0.0003s | 0s         | 0           |             | 0          | 0            | 0s           | 0             |
| template_redirect        | 7              | 0.001s  | 0s         | 0           | 100%        | 14         | 0            | 0s           | 0             |
| template_include:before  |                | 0.0002s | 0s         | 0           | 100%        | 2          | 0            | 0s           | 0             |
| template_include         | 0              | 0s      | 0s         | 0           |             | 0          | 0            | 0s           | 0             |
| wp_head:before           |                | 0.0012s | 0s         | 0           | 100%        | 10         | 0            | 0s           | 0             |
| wp_head                  | 25             | 0.0051s | 0s         | 0           | 95.37%      | 103        | 5            | 0s           | 0             |
| loop_start:before        |                | 0.0014s | 0s         | 0           | 100%        | 64         | 0            | 0s           | 0             |
| loop_start               | 0              | 0s      | 0s         | 0           |             | 0          | 0            | 0s           | 0             |
| loop_end:before          |                | 0.0056s | 0.0007s    | 2           | 97.39%      | 112        | 3            | 0s           | 0             |
| loop_end                 | 0              | 0s      | 0s         | 0           |             | 0          | 0            | 0s           | 0             |
| wp_footer:before         |                | 0.0049s | 0.0012s    | 4           | 94.44%      | 68         | 4            | 0s           | 0             |
| wp_footer                | 5              | 0.0004s | 0s         | 0           | 100%        | 4          | 0            | 0s           | 0             |
| wp_footer:after          |                | 0s      | 0s         | 0           |             | 0          | 0            | 0s           | 0             |
+--------------------------+----------------+---------+------------+-------------+-------------+------------+--------------+--------------+---------------+
| total (35)               | 83             | 0.2274s | 0.0042s    | 12          | 90.77%      | 701        | 29           | 0s           | 0             |
+--------------------------+----------------+---------+------------+-------------+-------------+------------+--------------+--------------+---------------+

Estos datos nos pueden ser de ayuda para encontrar cuellos de botella o puntos en los que hay algo que no corresponde. Algunas opciones son las de apagar todos los plugins, activar un theme de los «Twenty» e ir activando para ver su comportamiento segúns e van adaptando las configuraciones.

WP-CLI doctor

WP-CLI doctor realiza una búsqueda de posibles configuraciones que se pueden revisar.

Lo primero será instalarlo si no lo tienes ya.

wp package install wp-cli/doctor-command --allow-root

Una vez lo tengamos instalado, podemos ir a la carpeta donde tengamos el WordPress a analizar.

cd /home/example.com/public_html/

Una vez estemos en la carpeta donde tenemos nuestro WordPress, podremos realizar una serie de consultas.

Lo primero que haremos será listar todos aquellos análisis que son posibles.

wp doctor list --allow-root

Esto nos devolverá la lista de elementos a revisar.

+----------------------------+--------------------------------------------------------------------------------+
| name                       | description                                                                    |
+----------------------------+--------------------------------------------------------------------------------+
| autoload-options-size      | Warns when autoloaded options size exceeds threshold of 900 kb.                |
| constant-savequeries-falsy | Confirms expected state of the SAVEQUERIES constant.                           |
| constant-wp-debug-falsy    | Confirms expected state of the WP_DEBUG constant.                              |
| core-update                | Errors when new WordPress minor release is available; warns for major release. |
| core-verify-checksums      | Verifies WordPress files against published checksums; errors on failure.       |
| cron-count                 | Errors when there's an excess of 50 total cron jobs registered.                |
| cron-duplicates            | Errors when there's an excess of 10 duplicate cron jobs registered.            |
| file-eval                  | Checks files on the filesystem for regex pattern eval\(.*base64_decode\(.*.  |
| option-blog-public         | Confirms the expected value of the 'blog_public' option.                       |
| plugin-active-count        | Warns when there are greater than 80 plugins activated.                        |
| plugin-deactivated         | Warns when greater than 40% of plugins are deactivated.                        |
| plugin-update              | Warns when there are plugin updates available.                                 |
| theme-update               | Warns when there are theme updates available.                                  |
| cache-flush                | Detects the number of occurrences of the wp_cache_flush() function.          |
| php-in-upload              | Warns when a PHP file is present in the Uploads folder.                        |
| language-update            | Warns when there are language updates available.                               |
+----------------------------+--------------------------------------------------------------------------------+

Para hacer una prueba, por ejemplo autoload-options-size podemos ejecutar el siguiente comando.

wp doctor check autoload-options-size --allow-root

Que nos devolverá un mensaje similar a este:

+-----------------------+---------+-------------------------------------------------------------------+
| name                  | status  | message                                                           |
+-----------------------+---------+-------------------------------------------------------------------+
| autoload-options-size | success | Autoloaded options size (13.78kb) is less than threshold (900kb). |
+-----------------------+---------+-------------------------------------------------------------------+

El status puede ser uno de los siguientes:

  • success: todo es correcto
  • warning: hay algo a mejorar
  • error: hay un problema

Sobre este documento

Este documento está regulado por la licencia EUPL v1.2, publicado en WP SysAdmin y creado por Javier Casares. Por favor, si utilizas este contenido en tu sitio web, tu presentación o cualquier material que distribuyas, recuerda hacer una mención a este sitio o a su autor, y teniendo que poner el material que crees bajo licencia EUPL.

Servicios de Administración de Sistemas WordPress

¿Tienes un sitio web con WordPress de alto tráfico? ¿Eres una Agencia con servidores con cPanel, Plesk u otro panel en los que mantienes WordPress para tus clientes?

Si es así y te interesa un servicio profesional de mantenimiento de infraestructura WordPress y de mejora del rendimiento de tus sitios web o los de tus clientes, contacta conmigo.