PHP code example of showclix / cube-php

1. Go to this page and download the library: Download showclix/cube-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

showclix / cube-php example snippets


// Create a Client pointed at a local collector and evaluator
$client = \Cube\Client::createHttpClient(array(
    'collector' => array(
        'host' => 'localhost',
        'port' => 1080,
    ),
    'evaluator' => array(
        'host' => 'localhost',
        'port' => 1081,
    ),
    'secure' => true,
));

$res = $client->metricGet(array(
    'expression' => 'sum(cube_request)',
    'step' => \Cube\Client::INT_ONE_MINUTE,
    'limit' => 100,
));

echo "There were {$res[0]['value']} hits during {$res[0]['time']}";

array(
    'collector' => array(
        'host' => 'localhost',
        'port' => 1080,
    ),
    'evaluator' => array(
        'host' => 'localhost',
        'port' => 1081,
    ),
    'secure' => true,
)

array(
    'type' => 'example',
    'time' => time(),
    'data' => array(
        'key' => 'value',
    ),
)

$query = array(
    'expression' => 'request.eq(path, "search")',   // cube expression
    'limit' => 10,                                  // limit (optional)
);
$client->metricGet($query);

$query = array(
    'expression' => 'sum(type_name)',   // cube expression
    'start' => strtotime('-1 day'),     // start time (optional)
    'stop' => time(),                   // end time (optional)
    'limit' => 10,                      // limit (optional)
    'step' => Client::INT_ONE_MINUTE,   // time grouping interval
);
$res = $client->metricGet($query);
echo "There were {$res[0]['value']} during {$res[0]['time']}";