casperengl / cron-ms
Runs cron jobs based on milliseconds, instead of minutes, hours, days, weeks and years
dev-master
2020-06-03 05:08 UTC
Requires
- nesbot/carbon: ^2.35
Requires (Dev)
- larapack/dd: ^1.1
- nunomaduro/collision: ^5.0.0-BETA1
- nunomaduro/phpinsights: ^1.14
- pestphp/pest: ^0.1.5
- phpunit/phpunit: ^9.0
This package is auto-updated.
Last update: 2024-03-29 21:55:45 UTC
README
This library makes it easy to run a piece of code, every X milliseconds or seconds.
// Initialization and running // From milliseconds $cron = CronMs::fromMs(5000, function ($i /* each iteration count is returned here, start at 0 */) { // ... your code }); // From seconds $cron = CronMs::fromSeconds(5, function ($i /* each iteration count is returned here, start at 0 */) { // ... your code }); // Initialization only // You can also start the process yourself later. // Just pass false as the third (3rd) parameter $cron = CronMs::fromMs(5000, function ($i /* each iteration count is returned here, start at 0 */) { // ... your code }, false /* disables automatic run */); // Some other code // Some time later $cron->run(); // Properties // You can access `$ms`, `$start_timestamp` and `$startTime` from the CronMs instance $cron = CronMs::fromMs(5000, function ($i /* each iteration count is returned here, start at 0 */) { // ... your code }); $cron->ms // 5000 $cron->start_timestamp // unix timestamp $cron->start // Carbon\Carbon instance
Testing
Run the ./vendor/bin/phpunit
(optionally with the --testdox
parameter, for pretty output). Be aware, tests are longrunning. This is because each test runs the u_sleep()
method internally.