xhgui を docker を使って構築します。手間を省き汎用性があるようにできます。
Contents
xhgui
xhgui(確認用)
xhgui を docker で構築します。
ダウンロード
git clone https://github.com/perftools/xhgui
構築
1 2 |
cd xhgui docker-compose up -d |
確認
下記コンテナを確認します。
- xhgui_app_1
- xhgui_mongo_1
- xhgui_web_1
kitematic でした場合
xhgui_web_1 の WEB PREVIEW リンクから確認用サイトへ遷移できます。
xhgui(プロファイリング用)
解析する xhprof 導入済みサーバーに xhgui 用の設定を導入します。
ダウンロード
任意の箇所へ設置します。下記では「/var/www/html」としています。
1 2 |
cd /var/www/html git clone https://github.com/perftools/xhgui-collector |
composer
1 2 |
cd xhgui-collector composer install |
設定
xhgui 用に環境変数を設定します。
カスタム用 config ファイルを設定します。
1 2 3 |
cd /path/to/xhgui-collector cp -a ./config/config.default.php ./config/config.php vim ./config/config.php |
今回は docker 用に下記に変更します。
1 2 |
// define('XHGUI_MONGO_URI', '127.0.0.1:27017'); define('XHGUI_MONGO_URI', '192.168.99.100:27017'); |
事前実行
php.ini を編集して解析開始を本処理が行われる前に実行するようにします。
1 |
auto_prepend_file = /path/to/xhgui-collector/external/header.php |
または、.htaccess を編集
1 |
php_value auto_prepend_file /path/to/xhgui-collector/external/header.php |
直接指定するときは
php ファイルで呼び出し
1 |
require '/path/to/xhgui-collector/external/header.php'; |
あるいは、下記で処理のプログラムの実行前に指定したファイルを読み込むようにすることができます。
1 |
php -d auto_prepend_file=/path/to/xhgui-collector/external/header.php xxx.php |
項目
- Recent
最近のデータを表示 - Longest wall time
処理時間順 - Most CPU
CPU の負荷順 - Most memory
メモリ使用量順 - Custom View
カスタム表示 - Watch Functions
ウォッチ機能 - Waterfall
ウォーターフォール表示 - Search
条件を設定して抽出します。
使い方
docker コンテナの xhgui_web_1 コンテナへアクセスします。
http://192.168.99.100:xxxxx/
MongoDB
php にmongo 拡張モジュール(旧)を拡張します。
今回はMongoClientクラスを使っている関係でmongoドライバーをインストールします。
※現在は MongoDB 拡張モジュールを使うべきです。
インストール
debian/ubuntu
1 2 |
apt-get install mongodb mongo --host 192.168.99.100 --port 27017 |
centos
1 2 |
yum install mongodb mongo --host 192.168.99.100 --port 27017 |
PHP 拡張モジュール追加
拡張モジュールをインストールします。
1 2 3 4 5 6 7 |
cd /usr/local/lib git clone https://github.com/mongodb/mongo-php-driver-legacy.git cd mongo-php-driver-legacy phpize ./configure make all make install |
(mongodbの場合)
1 |
pecl install mongodb |
インストール確認
インストール先を確認
1 2 |
ls -al /usr/local/lib/php/extensions/no-debug-non-zts-20131226/ /usr/local/lib/php/extensions/no-debug-non-zts-20131226/mongo.so |
インストールした先がPHP拡張ディレクトリと同じか確認します。
1 |
php -i | grep extension_dir |
INI編集
php.ini を編集します。
1 |
extension = mongo.so |
備考
項目
素の xhprof の場合
- Function Name
コールされた関数 - Calls
コールされた数 - Calls%
コール数の割合 - Incl. Wall Time
処理時間 - IWall%
処理時間の割合 - Excl. Wall Time
関数の処理時間(呼ばれた関数の処理時間は除外) - EWall%
関数の処理時間の割合
関連リンク
xhgui
https://github.com/perftools/xhgui
https://github.com/perftools/xhgui-collector
mongodb
https://www.php.net/manual/ja/class.mongoclient.php
https://github.com/mongodb/mongo-php-driver-legacy
https://pecl.php.net/package/mongo
https://pecl.php.net/package/mongodb