Groongaのソースに入っている管理ページを使用
index.phpを追加します。
GroongaのPHPバインディングをインストール
リクエスト受け取りスクリプトの作成
$gdb = new Groonga('localhost', 10043);
/* リクエストURLからコマンドクエリを整形 */
$param = '';
$query = $_SERVER['REQUEST_URI'];
$pos = strrpos($query, '?');
if (false !== $pos) {
$param = substr($query, $pos);
$query = substr($query, 0, $pos);
}
/* クエリ送信 */
$start = microtime(true);
$response = $gdb->query($query . '.json'.$param, 1);
$end = microtime(true);
/* [HEADER, BODY]形式に整形 */
$result = array(
array(
0,
microtime(true),
$end - $start
),
$response
);
/* コンテントタイプの送信 */
header("Content-Type: application/json; charset=utf-8");
header('X-Content-Type-Options: nosniff');
/* JSON出力 */
if (empty($_GET['callback'])){
echo json_encode($result);
} else {
echo $_GET['callback'].'('.json_encode($result).')';
}
nginx設定
server {
server_name sheeps.me;
root /usr/share/sheeps.me/www;
index index.html index.php;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
# With php5-fpm:
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
# serve static files directly
location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|html|xml|bmp|swf|wmv)$ {
root /usr/share/sheeps.me/www;
access_log off;
expires 30d;
}
location ~ /\.ht {
deny all;
}
}
ファイルが存在しない場合にindex.phpへアクセスするように設定します。
/d/status などのURLを取得してコマンドへ整形します。
キャプチャ
こんな感じで出来ました。