AndyB
Well-known member
Hello,
Currently with my ElasticSearch v1.2 add-on located here:
https://xenforo.com/community/resources/elasticsearch.4218/
I have the following code which works very well to get all the ElasticSearch indexes.
What I would like to do is replace this code with code that doesn't use cURL.
Any help greatly appreciated.
Thank you.
Currently with my ElasticSearch v1.2 add-on located here:
https://xenforo.com/community/resources/elasticsearch.4218/
I have the following code which works very well to get all the ElasticSearch indexes.
PHP:
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => 'http://localhost:' . $esPort . '/_stats',
CURLOPT_USERAGENT => $_SERVER['HTTP_USER_AGENT'],
));
// get data
$dataJson = curl_exec($curl);
curl_close($curl);
// json decode
$dataArray = json_decode($dataJson, true);
// throw error if index missing
if (empty($dataArray))
{
throw new XenForo_Exception(new XenForo_Phrase('elasticsearch_index_missing'), true);
}
foreach ($dataArray AS $k => $v)
{
if ($k == 'indices')
{
foreach ($v AS $k2 => $v2)
{
$index = $k2;
$size = $v2['primaries']['store']['size_in_bytes'];
// convert to MB
$base = log($size) / log(1024);
$size = pow(1024, $base - floor($base));
$size = floor($size);
$size = $size . 'MB';
// create stats array
$stats[] = array(
'index' => $index,
'size' => $size
);
}
}
}
What I would like to do is replace this code with code that doesn't use cURL.
Any help greatly appreciated.
Thank you.