macな開発環境にxhguiを導入する

Twitter ツイート Hatena Bookmark ブックマーク

こんなツイートを見つけてしまったので早速試してみる事にしました!!!

とりあえずまずはxhprofを入れる。ついでにmongoもwww

1
2
3
$ brew install php53-xhprof
$ brew install mongodb
$ brew install php53-mongo

mongoDBが起動しているか確認する。

1
2
$ mongostat
couldn't connect to [127.0.0.1] couldn't connect to server 127.0.0.1

起動していないので起動する。

1
$ mongod -dbpath /usr/local/var/mongodb/ --logpath /usr/local/var/log/mongodb/mongodb.log &

続いてxhguiをcloneしてくる、その後cacheディレクトリのパーミッションを777にしとく

1
2
3
$ cd /usr/local/share
$ git clone https://github.com/preinheimer/xhgui.git
$ chmod 777 xhgui/web/cache

apacheにxhguiの設定をする

1
$ vim /usr/local/etc/apache2/extra/httd-vhost.conf

設定例:https://gist.github.com/663cdbfd2efcdc9a8cfc

続いてhostsも書き換えとく

1
2
3
4
5
$ sudo vim /etc/hosts

# 以下を一番下に追記
127.0.0.1       xhgui.local
::1             xhgui.local

これで一応うごくようになったとおもうので、ブラウザで

http://xhgui.local

にアクセスして確認してみましょう。

何回かリロードするとこんな感じに表示されているかと思います。

デフォルトの状態だとxhgui.localにアクセスする度にxhprofのデータ記録されてしまい、非常にうざいです。
なので、記録されないようにphpファイルを若干修正します。

1
$ vim /usr/local/share/xhgui/web/webroot/index.php

以下のように書き換え(コメントアウト)してください。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
require dirname(__DIR__) . '/app/bootstrap.php';

//xhprof_enable(XHPROF_FLAGS_CPU | XHPROF_FLAGS_MEMORY);

$m = new Mongo();
$db = $m->xhprof;
$collection = $db->results;


//Let's get results from the database
$res = $collection->find()->sort(array("meta.SERVER.REQUEST_TIME" => -1))->limit(DISPLAY_LIMIT);
$template = load_template('runs/list.twig');
echo $template->render(array(
    'runs' => $res
));
flush();

//Store results


function _xhGetMeta()
{
    $meta = array(
        'url' => $_SERVER['REQUEST_URI'],
        'SERVER' => $_SERVER,
        'get' => $_GET,
        'env' => $_ENV,
        'simple_url' => simpleUrl($_SERVER['REQUEST_URI']),
    );  
    return $meta;
}
//$profile = xhprof_disable();
//$data['meta'] = _xhGetMeta();
//$data['profile'] = $profile;

//$collection->insert($data);
//$m = new Mongo();
//$db = $m->xhprof;
//$collection = $db->results;

これで後は自分でプロファイルとりたい場所に適当に/usr/local/share/xhgui/external/header.phpをrequireしてあげれば動くと思います。

comments powered by Disqus
Built with Hugo
テーマ StackJimmy によって設計されています。