Skip to content

Instantly share code, notes, and snippets.

@JCook21
Last active December 14, 2015 16:48
Show Gist options
  • Save JCook21/5117548 to your computer and use it in GitHub Desktop.
Save JCook21/5117548 to your computer and use it in GitHub Desktop.
Testing using timers for data imports.
<?php
require dirname(__DIR__) . '/vendor/autoload.php';
class Test
{
protected $counter = 1;
public function __invoke($signature, $loop)
{
echo "In iteration {$this->counter}\n";
$this->counter++;
$time = $this->counter % 2 ? 1 : 5;
echo "Next callback in $time seconds\n";
$loop->addTimer($time, $this);
}
}
$loop = new React\EventLoop\StreamSelectLoop;
//$loop = new React\EventLoop\LibEventLoop;
printf("Loop instance of %s\n", get_class($loop));
$loop->addTimer(1, new Test);
$loop->addPeriodicTimer(5, function () {
$memory = memory_get_usage() / 1024;
$formatted = number_format($memory, 3).'K';
echo "Current memory usage: {$formatted}\n";
});
$loop->run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment