I am trying to run EvPeridoc to log data periodically (every 15 minutes, i.e 900 seconds) to a file.
<?php
$tolog = '';
$w = new EvPeriodic(fmod(Ev::now(), 900), 900, NULL, function($w, $revents)
{
file_put_contents("log.txt", $tolog . PHP_EOL, FILE_APPEND | LOCK_EX);
});
Ev::run(Ev::RUN_NOWAIT);
echo "Started periodic @ " . date("Y-m-d h:i:sa") . PHP_EOL;
for (;;) {
$tolog = "Update @ " . date("Y-m-d h:i:sa");
}
The periodic never fires but the app goes into the for loop. If I change the line Ev::run(Ev::RUN_NOWAIT); to Ev::run(); then the script never reaches the loop.
So the question is how do I pipe this code to be able to fire logging routine every 15 mins?
EDIT: Just to clarify - the infinite loop at the end of this script generates the data to be logged (and assigns the value to the $tolog gloabl variable). What I'd like EvPeriodic to do is pick up that (global) variable every 15 minutes and append it to a file.