Last active
December 14, 2015 16:48
-
-
Save JCook21/5117548 to your computer and use it in GitHub Desktop.
Testing using timers for data imports.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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