public function flush() { $this->socket->open(); $metrics = array_map(function (MetricInterface $metric) { return $metric->getData(); }, $this->queue); $packets = $this->fillPackets($metrics); foreach ($packets as $packet) { $this->socket->write($packet); } $this->queue = []; $this->socket->close(); }