/** * @param Message $message * * @return bool */ public function write(Message $message) { $attempt = 1; $content = $message->getPayload(); $contentLength = strlen($content); try { while ((int) $this->stream->write($content) !== $contentLength && $attempt++ < self::RETRY) { Sleep::millisecond(self::RETRY_INTERVAL); } $success = $attempt < self::RETRY; } catch (\Exception $e) { $this->logger->warning('An error occurred writing to APNS stream', array('error_message' => $e->getMessage())); $success = false; } return $success; }
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; } }