Created
December 5, 2014 03:54
-
-
Save Yujiro3/c4965e11cbcb2c07d9e1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* GroongaHTTPフォーマット出力 | |
* | |
* PHP versions 5.4.x | |
* | |
* index.php : https://gist.github.com/Yujiro3/ | |
* Copyright (c) 2011-2014 sheeps.me All Rights Reserved. | |
* | |
* @package exchanger | |
* @copyright Copyright (c) 2014 sheeps.me | |
* @author Yujiro Takahashi <yujiro3@gmail.com> | |
* @filesource | |
*/ | |
$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).')'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment