Create a gist now

Instantly share code, notes, and snippets.

@naoa /grn_search.php
Last active Aug 29, 2015

Embed
What would you like to do?
<?php
$category_file = $argv[1];
$rc = 1;
$startTimeAll = microtime(true);
$fp = fopen($category_file, 'r');
while(!feof($fp)){
$line = fgets($fp);
$line = str_replace(array("\r\n","\r","\n"),'',$line);
if($line != ""){
$startTime = microtime(true);
$query = $line;
$query = urlencode($query);
$url="http://localhost:10041/d/select?table=text&match_columns=title||text&limit=0&match_escalation_threshold=-1&query=" . $query;
$req="GET";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_PORT, 10041);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $req);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
$data = curl_exec ($ch);
curl_close ($ch);
$endTime = microtime(true);
$elapsedTime = $endTime - $startTime;
//$decode_data = json_decode( $data, true);
echo $rc . "," . $elapsedTime . "\n";
$rc++;
}
}
$endTimeAll = microtime(true);
$elapsedTimeAll = $endTimeAll - $startTimeAll;
$rc--;
echo "Total(" . $rc . ") = " . $elapsedTimeAll . "\n";
echo "Average = " . $elapsedTimeAll/$rc . "\n";
fclose($fp)
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment