LoginSignup
2
2

More than 5 years have passed since last update.

PHP+nginxでGroonga管理ページを使う

Last updated at Posted at 2014-12-05

Groongaのソースに入っている管理ページを使用

Groonga管理ページ

001.png

index.phpを追加します。

GroongaのPHPバインディングをインストール

PHPバインディング

リクエスト受け取りスクリプトの作成

index.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を取得してコマンドへ整形します。

キャプチャ

002.png

003.png

004.png

こんな感じで出来ました。

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2