public function tick() { if (null === $this->pdo) { $this->logger->warning('Unable to ping sql server, service pdo is unavailable'); return; } //if connection is persistent we don't need to ping if (true === $this->pdo->getAttribute(\PDO::ATTR_PERSISTENT)) { return; } try { $startTime = microtime(true); $this->pdo->query('SELECT 1'); $endTime = microtime(true); $this->logger->notice(sprintf('Successfully ping sql server (~%s ms)', round(($endTime - $startTime) * 100000), 2)); } catch (\PDOException $e) { $this->logger->emergency('Sql server is gone, and unable to reconnect'); throw $e; } }
/** * Launches a command as a separate process. * * The '--process-timeout' parameter can be used to set the process timeout * in seconds. Default timeout is 300 seconds. * If '--ignore-errors' parameter is specified any errors are ignored; * otherwise, an exception is raises if an error happened. * * @param string $command * @param array $params * @param LoggerInterface|null $logger * * @return integer The exit status code * @throws \RuntimeException if command failed and '--ignore-errors' parameter is not specified */ public function runCommand($command, $params = [], LoggerInterface $logger = null) { $params = array_merge(['command' => $command], $params); if ($this->env && $this->env !== 'dev') { $params['--env'] = $this->env; } $ignoreErrors = false; if (array_key_exists('--ignore-errors', $params)) { $ignoreErrors = true; unset($params['--ignore-errors']); } $pb = new ProcessBuilder(); $pb->add($this->getPhp())->add($this->consoleCmdPath); if (array_key_exists('--process-timeout', $params)) { $pb->setTimeout($params['--process-timeout']); unset($params['--process-timeout']); } else { $pb->setTimeout($this->defaultTimeout); } foreach ($params as $name => $val) { $this->processParameter($pb, $name, $val); } $process = $pb->inheritEnvironmentVariables(true)->getProcess(); if (!$logger) { $logger = new NullLogger(); } $exitCode = $process->run(function ($type, $data) use($logger) { if ($type === Process::ERR) { $logger->error($data); } else { $logger->notice($data); } }); // synchronize all data caches if ($this->dataCacheManager) { $this->dataCacheManager->sync(); } $this->processResult($exitCode, $ignoreErrors, $logger); return $exitCode; }