WP CLI

個人的に気になったWP-CLIコマンドいろいろ

https://github.com/wp-cli をぼーっと見てたら「あれ、こんなのあったっけ」というコマンドがいくつかあったのでピックアップ。
--format=jsonで取り出していろいろ運用監視系で使えそうな予感です。

以前に紹介したコマンド

以前に別記事として紹介したコマンドもありますので、そちらもぜひ。

wp-config.phpの情報を取ってくるwp config getコマンド

https://github.com/wp-cli/config-command

wp-config.phpの情報を出力してくれます。
移行前のサイトの設定を確認したい時、これ一発で情報を一通り見れるのが便利そうかなと思います。

$ wp config get
+-----------------------------+------------------------------------------------------------------+----------+
| key                         | value                                                            | type     |
+-----------------------------+------------------------------------------------------------------+----------+
| table_prefix                | wp_                                                              | variable |
| DB_NAME                     | example                                                          | constant |
| DB_USER                     | wp_xxxxxxxxxxxxx                                                 | constant |
| DB_PASSWORD                 | XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX                                 | constant |
| DB_HOST                     | localhost                                                        | constant |
| DB_CHARSET                  | utf8                                                             | constant |
| DB_COLLATE                  |                                                                  | constant |
| AUTH_KEY                    | XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX | constant |
| SECURE_AUTH_KEY             | XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX | constant |
| LOGGED_IN_KEY               | XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX | constant |
| NONCE_KEY                   | XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX | constant |
| AUTH_SALT                   | XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX | constant |
| SECURE_AUTH_SALT            | XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX | constant |
| LOGGED_IN_SALT              | XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX | constant |
| NONCE_SALT                  | XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX | constant |
| WP_DEBUG                    |                                                                  | constant |
| VAULTPRESS_DISABLE_FIREWALL | 1                                                                | constant |
| IS_AMIMOTO                  | 1                                                                | constant |
| NCC_CACHE_DIR               | /var/cache/nginx/proxy_cache                                     | constant |
| DISALLOW_FILE_EDIT          | 1                                                                | constant |
| local-config.php            | /var/www/vhosts/example.com/local-config.php                     | includes |
| local-salt.php              | /var/www/vhosts/example.com/local-salt.php                       | includes |
+-----------------------------+------------------------------------------------------------------+----------+

ちなみにAMIMOTOはlocal-config.phplocal-salt.phpにDBやSALT情報を移しているのですが、問題なくロードしてくれています。

WordPressのパフォーマンスチェックに使えそうなwp profile

https://github.com/wp-cli/profile-command
クエリの実行時間やフックの数などをプロファイリングしてくれます。

インストール方法

$ wp package install git@github.com:wp-cli/profile-command.git

プロファイルを実行した例

$ wp profile stage
+------------+---------+------------+-------------+-------------+------------+--------------+-----------+------------+--------------+---------------+
| stage      | time    | query_time | query_count | cache_ratio | cache_hits | cache_misses | hook_time | hook_count | request_time | request_count |
+------------+---------+------------+-------------+-------------+------------+--------------+-----------+------------+--------------+---------------+
| bootstrap  | 1.0439s | 0.0423s    | 13          | 94.36%      | 435        | 26           | 0.3518s   | 3053       | 0.0356s      | 1             |
| main_query | 0.0016s | 0.0001s    | 2           | 96.88%      | 31         | 1            | 0.0005s   | 76         | 0s           | 0             |
| template   | 1.3548s | 0.0133s    | 20          | 97.01%      | 1882       | 58           | 1.2786s   | 3351       | 1.2225s      | 1             |
+------------+---------+------------+-------------+-------------+------------+--------------+-----------+------------+--------------+---------------+
| total (3)  | 2.4003s | 0.0557s    | 35          | 96.08%      | 2348       | 85           | 1.6308s   | 6480       | 1.2582s      | 2             |
+------------+---------+------------+-------------+-------------+------------+--------------+-----------+------------+--------------+---------------+

fieldsなどを指定することもできます。

$ wp profile stage bootstrap --fields=hook,time,cache_ratio --spotlight
+--------------------------+---------+-------------+
| hook                     | time    | cache_ratio |
+--------------------------+---------+-------------+
| muplugins_loaded:before  | 0.0974s | 25%         |
| muplugins_loaded         | 0.0001s | 50%         |
| plugins_loaded:before    | 0.0492s | 80.2%       |
| plugins_loaded           | 0.0668s | 100%        |
| after_setup_theme:before | 0.0123s | 100%        |
| init                     | 0.0219s | 99.08%      |
| wp_loaded:after          | 0.0271s |             |
+--------------------------+---------+-------------+
| total (7)                | 0.2748s | 75.71%      |
+--------------------------+---------+-------------+

WP-CLI、使いこなせると便利ですのでみなさんもぜひ。


Random posts

GitHubHomeEnglish