Search by

coercive / chronos

Coercive

Coercive Chronos Log Utility

Package info

github.com/Coercive/Chronos

Homepage

pkg:composer/coercive/chronos

Statistics

Installs: 1 381

Dependents: 0

Suggesters: 0

Stars: 1

Open Issues: 0

2.1.0 2026-10-13 06:56 UTC

This package is auto-updated.

Last update: 2026-10-13 06:58:34 UTC


README

The Chronos Log Utility allows you to accurately measure the execution time of a script, and that from the server startup.

Compatible PHP 7.4 → 8.5

Get

composer require coercive/chronos

Usage

use Coercive\Utility\Chronos\Chronos;

# Monitor a sleep
Chronos::start('sleep');
sleep(2);
Chronos::stop('sleep');

# Monitor some code process
Chronos::start('sha1');
$data = [];
foreach (range(0, 1000000) as $i) {
	$data[] = sha1($i);
}
Chronos::stop('sha1');

# Monitor an other code process with laps
Chronos::start('waits');
foreach (range(0, 3) as $seconds) {
	sleep($seconds);
	Chronos::lap('waits', 'Waiting ' . $seconds . ' seconds');
}
Chronos::stop('waits');

# And now : retrieve monitoring data !

# Full diff of all process (from the first start to the last stop)
error_log(print_r(Chronos::diff(), true));

# Diff of sha1 process
error_log(print_r(Chronos::diff('sha1'), true));

# Retrieve full data as array
error_log(print_r(Chronos::get(), true));

# Retrieve one monitor
error_log(print_r(Chronos::get('waits'), true));

Notes

  • lap() and stop() automatically start a monitor that does not exist yet.
  • diff() on a monitor not stopped yet measures it until now.
  • stop() also records the peak memory usage (memory_peak).
# Does a monitor exist ?
Chronos::has('sha1');

# Remove one monitor, or all
Chronos::reset('sha1');
Chronos::reset();

# Memory measurement mode
# true (default) : memory allocated from system (by 2 MB chunks, coarse)
# false : memory really used by the script (more accurate)
Chronos::setRealMemoryUsage(false);

Tests

PHPUnit 12 requires PHP 8.3+ (the library itself stays compatible with PHP 7.4).

composer install
vendor/bin/phpunit