/**
* Create a new file driven handler instance.
*
* @param \Illuminate\Filesystem\Filesystem $files
* @param React\EventLoop\LoopInterface $loop
* @param string $path
*
* @return void
*/
public function __construct(Factory $factory, LoopInterface $loop, Server $server, $lifetime)
{
$this->factory = $factory;
$this->lifetime = $lifetime;
$this->server = $server;
$this->loop = $loop;
// PING redis connection every 5 minutes
// and try to reconnect on connection error
$this->timer = $loop->addPeriodicTimer(60 * 1, function () use($server) {
$this->promise->then(function ($client) use($server) {
$client->PING()->then(function ($pong) use($server) {
$server->log('Redis server responded ping with: %s', [$pong]);
return $pong == 'PONG';
}, function ($e) {
return $this->reconnectByError($e);
});
});
});
// server statistics for redis connection
$this->loop->addPeriodicTimer(60 * 30, function () {
$this->server->log('Server statistics to the last 30 minutes.');
$this->server->log('Best time of %fs, poor time of %fs and a average of %f seconds for total %d requests.', array_values($this->statistics));
$this->statistics = array('best' => 0, 'poor' => 0, 'avg' => 0, 'total' => 0);
});
}