1. Go to this page and download the library: Download jackgleeson/stats-collector 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/ */
jackgleeson / stats-collector example snippets
//get an instance of stats collector
$stats = Statistics\Collector\Collector::getInstance();
//add a stat
$stats->add("clicks", 45);
//get a stat
$clicks = $stats->get("clicks");
$clicks; // 45
//increment a stat
$stats->inc("clicks");
$clicks = $stats->get("clicks");
$clicks; // 46
$stats = Statistics\Collector\Collector::getInstance();
//add a custom namespace and add some stats to it
$stats->ns("crons.payments")
->add("total", 30)
->add("succeeded", 20)
->add("failed", 10);
// get payment cron stats using wildcard path
$paymentStats = $stats->getWithKey("crons.payments.*");
// $paymentStats contents
Array
(
[crons.payments.failed] => 10
[crons.payments.succeeded] => 20
[crons.payments.total] => 30
)
$stats = Statistics\Collector\Collector::getInstance();
$stats->start("timer");
// some lengthy process...
$stats->end("timer");
// get the exectuion time
$execution_time = $stats->diff('timer');
$stats = Statistics\Collector\Collector::getInstance();
//add a custom namespace and add some stats to it
$stats->ns("crons.payments")
->add("total", 30)
->add("succeeded", 20)
->add("failed", 10);
//export recorded stats to a txt file (see output below)
$exporter = new Statistics\Exporter\File("demo","outdir/dir");
$exporter->export($stats);
$stats = Statistics\Collector\Collector::getInstance();
$stats->ns("noahs.ark.passengers")
->add("humans", 2)
->add("aliens", 0)
->add("animal.cats", 3)
->add("animal.dogs", 6)
->add("animal.birds", 25);
// total number of passengers on noahs ark
$totalPassengers = $stats->sum("noahs.ark.passengers.*"); // 36
$totalAnimals = $stats->sum("*passengers.animal*"); // 34
$totalCatsAndDogs = $stats->sum("*passengers.animal.[c,d]*"); // 9