PHP code example of phperf / percentiller

1. Go to this page and download the library: Download phperf/percentiller 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/ */

    

phperf / percentiller example snippets


$stats = new \Phperf\Percentiller();

// approximation level, more buckets - higher distribution definition for more CPU and memory
$stats->maxBuckets = 10;

// capture values and meta for 5 items with lowest values
$stats->captureBottomItems = 5;

// capture values and meta for 3 items with highest values
$stats->captureTopItems = 3;

.......

// somewhere in data streamer/iterator, replace $event with your data element
$stats->add($event->getResponseTime(), $event->getQueryInfo());

.......

// statistics retrieval

// 95% events had response time not greater than:
$stats->bottomPercentile(0.95);

// 10% events took longer or equal to:
$stats->topPercentile(0.1);

// get information on slowest events
$stats->getTopMetas();

// get information on slowest events
$stats->getBottomMetas();

// iterate through distribution
foreach ($stats->buckets as $bucket) {
    print_r($bucket);
    /*
    Array
    (
        [0] => 41.558                       // minival value
        [1] => 50.95                        // maximal value
        [2] => 137                          // count
        [3] => Array                        // sample meta
            (
                [somedata] => somevalue
            )

    )
    */
}