/** * Transmit the metrics in `$data` over UDP * * @param string[] $data * @param float [$sampleRate=1] */ public function send($data, $sampleRate = 1) { if ($sampleRate < 1) { $data = StatsD::getSampledData($data, $sampleRate); } if (empty($data)) { return; } try { $fp = fsockopen("udp://{$this->host}", 8125); if (!$fp) { return; } foreach ($data as $stat => $value) { fwrite($fp, "{$stat}:{$value}"); } fclose($fp); } catch (Exception $e) { } }