「Php/速度改善/XHProf/解析画面設置」の版間の差分
提供: 初心者エンジニアの簡易メモ
(ページの作成:「 ==解析UI設置== *xhprof_html *xhprof_lib ==XHProfの使い方== xhprof_enable(); // 処理 xhprof_disable(); ==コード例 †== xhprof/XhprofCustom.php <?php...」) |
(→コード例 †) |
||
| 行46: | 行46: | ||
register_shutdown_function(array('XhprofCustom', 'finish')); | register_shutdown_function(array('XhprofCustom', 'finish')); | ||
} | } | ||
| + | |||
| + | ==xhprof_htmlを公開領域からアクセスできるように== | ||
| + | ln -s /usr/local/src/xhprof-0.9.4/xhprof_html /var/www/html/xhprof_html | ||
| + | |||
==以下エラーが出るときはxdebugなどのxhprof以外のプロファイラーをuninstallする== | ==以下エラーが出るときはxdebugなどのxhprof以外のプロファイラーをuninstallする== | ||
Fatal error: Class ~ not found | Fatal error: Class ~ not found | ||
2018年5月17日 (木) 16:48時点における最新版
目次
解析UI設置
- xhprof_html
- xhprof_lib
XHProfの使い方
xhprof_enable(); // 処理 xhprof_disable();
コード例 †
xhprof/XhprofCustom.php
<?php
class XhprofCustom
{
static private $_starttime;
public function start()
{
if ($_SERVER['REQUEST_URI'] == "/favicon.ico") return;
xhprof_enable();
self::$_starttime = microtime(true);
}
// stop profiler
public function finish()
{
if ($_SERVER['REQUEST_URI'] == "/favicon.ico") return;
$xhprof_data = xhprof_disable();
$XHPROF_ROOT = dirname(__FILE__); // xhprofをインストールしたディレクトリ
$XHPROF_SOURCE_NAME = 'app_name'; // アプリ名とか識別する名前
include_once $XHPROF_ROOT . "/xhprof_lib/utils/xhprof_lib.php";
include_once $XHPROF_ROOT . "/xhprof_lib/utils/xhprof_runs.php";
$xhprof_runs = new XHProfRuns_Default();
$run_id = $xhprof_runs->save_run($xhprof_data, $XHPROF_SOURCE_NAME);
$xhprof_log_file = "xhprof.html";
$xhprof_log_path = $XHPROF_ROOT.'/'.$xhprof_log_file;
$time = floor((microtime(true) - self::$_starttime) * 100000) / 100;
// ビューアへのリンクログ
file_put_contents($xhprof_log_path, date("Y-m-d H:i:s")." {$time} <a href=\"./xhprof_html/index.php?run=$run_id&source=$XHPROF_SOURCE_NAME\">{$_SERVER['REQUEST_URI']}</a><br />\n", FILE_APPEND);
}
}
index.php
if (file_exists(dirname(__FILE__) . '/xhprof/XhprofCustom.php')) {
require_once dirname(__FILE__) . '/xhprof/XhprofCustom.php';
XhprofCustom::start();
register_shutdown_function(array('XhprofCustom', 'finish'));
}
xhprof_htmlを公開領域からアクセスできるように
ln -s /usr/local/src/xhprof-0.9.4/xhprof_html /var/www/html/xhprof_html
以下エラーが出るときはxdebugなどのxhprof以外のプロファイラーをuninstallする
Fatal error: Class ~ not found
