coercive / chronos
Coercive Chronos Log Utility
2.1.0
2026-10-13 06:56 UTC
Requires
- php: >=7.4
Requires (Dev)
- phpunit/phpunit: ^12
Suggests
None
Provides
None
Conflicts
None
Replaces
None
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()andstop()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