PHPのCacheToolをインストール

AIにサーバー稼働状況を分析レポートとして報告させるバッチを作成しているときの覚書。
Gemini 3 Pro Previewと対話。

環境: FreeBSD 14.3-RELEASE-p7, PHP 8.3.23, CacheTool 10.0.0

PHP OPcacheの統計情報を下記コマンドで取得できるかと思ったけど、PHP-FPMで実行されるOPcache統計情報ではなくPHP CLIのOPcache統計情報だった。
# php -r 'print_r(opcache_get_status(false));' 2>/dev/null

ちゃんとPHP-FPM経由で「opcache_get_status」を実行させる必要がある。

opcache-guiをインストール済み。
これをcurlコマンドで読み取っていいと思う。
参考: amnuts/opcache-gui: A clean, effective and responsive interface for Zend OPcache

CacheToolというツールをGemini先生にお勧めされたのでインストールしてみた。


1. CacheToolをインストール

Phar 拡張モジュールをインストール。
# pkg search phar
# pkg install php83-phar

公式ドキュメントの通りにインストール。
参考: CacheTool - Manage cache in the CLI | cachetool
# curl -sLO https://github.com/gordalina/cachetool/releases/latest/download/cachetool.phar
# chmod +x cachetool.phar

/usr/local/bin に移動しつつ、名前を 'cachetool' に変更。
# mv cachetool.phar /usr/local/bin/cachetool

確認。
# cachetool --version

CacheTool 10.0.0


2. OPcache統計情報を取得

コマンドリストを表示。
# cachetool list

fcgiオプションにUnix Socketファイルを指定して実行。
「/usr/local/etc/php-fpm.d/www.conf」に記載。
# cachetool opcache:status --fcgi=/var/run/php-fpm.sock

+----------------------+---------------------------------+
| Name                 | Value                           |
+----------------------+---------------------------------+
| Enabled              | Yes                             |
| Cache full           | No                              |
| Restart pending      | No                              |
| Restart in progress  | No                              |
| Memory used          | 1020.72 MiB                     |
| Memory free          | 515.28 MiB                      |
| Memory wasted (%)    | 0 b (0%)                        |
| Strings buffer size  | 8 MiB                           |
| Strings memory used  | 8 MiB                           |
| Strings memory free  | 24 b                            |
| Number of strings    | 80304                           |
+----------------------+---------------------------------+
| Cached scripts       | 16209                           |
| Cached keys          | 16738                           |
| Max cached keys      | 32531                           |
| Start time           | Thu, 01 Jan 2026 09:48:32 +0900 |
| Last restart time    | Never                           |
| Oom restarts         | 0                               |
| Hash restarts        | 0                               |
| Manual restarts      | 0                               |
| Hits                 | 13105766                        |
| Misses               | 17042                           |
| Blacklist misses (%) | 0 (0%)                          |
| Opcache hit rate     | 99.870134501701                 |
+----------------------+---------------------------------+



▼ 関連記事