Benjamin Eberlei, Open-Source Enthusiast and Doctrine Project Lead & Contributor, tweeted his first PHP extension from scratch wrapping the HdrHistogram C API

HdrHistogram is a high dynamic range histogram that supports recording and analyzing sampled data value counts across a configurable integer value range with configurable value precision within the range. Value precision is expressed as the number of significant digits in the value recording, and provides control over value quantization behavior across the value range and the subsequent value resolution at any given level.

HdrHistogram-PHP provides a wrapper for the C API, which usage is very similar to the C API :

$hdr = hdr_init(1, 3600000, 3);
hdr_record_value($hdr, 1337);
hdr_record_values($hdr, 42, 100);

printf(
'Mean: %d Min: %d Max: %d Count(42): %d Perc(95): %d',
hdr_mean($hdr),
hdr_min($hdr),
hdr_max($hdr),
hdr_count_at_value($hdr, 42),
hdr_value_at_percentile($hdr, 95)
);

$iter = hdr_iter_create($hdr);

while ($data = hdr_iter_next($iter)) {
printf(
'Value: %d-%d Count: %d, CountTo: %d',
$data['value'],
$data['highest_equivalent_value'],
$data['count_at_index'],
$data['count_to_index']
);
}

The PHP wrapper even if it implement most of the API, it’s still missing iterators (LinearIterator, LogIterator, and RecordedIterator) in addition to Serialization/Unserialization. Released under a New-BSD 2 Clause.

More information and download at : HdrHistogram-PHP, documentation in the HdrHistogram website.

LEAVE A REPLY

Please enter your comment!
Please enter your name here