/**
  * Code inspired by https://github.com/etsy/statsd/blob/master/examples/php-example.php
  */
 public static function doLog($logMethod, array $data, &$output)
 {
     list($host, $port, $types) = eZPerfLoggerINI::variableMulti('StatsdSettings', array('Host', 'Port', 'VariableTypes'));
     // Failures in any of this should be silently ignored
     try {
         $strings = array();
         foreach ($data as $varName => $value) {
             $type = isset($types[$varName]) && $types[$varName] != '' ? $types[$varName] : 'ms';
             $strings[] = static::transformVarName($varName) . ":{$value}|{$type}";
         }
         $fp = fsockopen("udp://{$host}", (int) $port, $errNo, $errStr);
         if (!$fp) {
             eZPerfLoggerDebug::writeWarning("Could not open udp socket to {$host}:{$port} - {$errStr}", __METHOD__);
             return;
         }
         if (eZPerfLoggerINI::variable('StatsdSettings', 'SendMetricsInSinglePacket') == 'enabled') {
             fwrite($fp, implode("\n", $strings));
         } else {
             foreach ($strings as $string) {
                 fwrite($fp, $string);
             }
         }
         fclose($fp);
     } catch (Exception $e) {
     }
 }
 /**
  * @see eZPerfLoggerStorage::insertStats
  * @see http://tools.ietf.org/html/rfc4180
  * @param array $data
  * @return bool
  */
 public static function insertStats(array $data)
 {
     list($csvfile, $separator, $quotes) = eZPerfLoggerINI::variableMulti('csvSettings', array('FileName', 'Separator', 'Quotes'));
     $addheader = false;
     if (!file_exists($csvfile)) {
         $addheader = true;
     }
     $fp = fopen($csvfile, 'a');
     if (!$fp) {
         return false;
     }
     if ($addheader) {
         fwrite($fp, "Timestamp{$separator}");
         fwrite($fp, implode($separator, eZPerfLoggerINI::variable('GeneralSettings', 'TrackVariables')));
         fwrite($fp, "{$separator}Date{$separator}IP Address{$separator}Response Status{$separator}Response size{$separator}URL\n");
     }
     foreach ($data as $line) {
         $data = array_merge(array($line['time']), $line['counters']);
         $data[] = date('d/M/Y:H:i:s O', $line['time']);
         $data[] = $line['ip'];
         $data[] = $line['response_status'];
         $data[] = $line['response_size'];
         $data[] = $quotes . str_replace($quotes, $quotes . $quotes, $line['url']) . $quotes;
         fwrite($fp, implode($separator, $data) . "\n");
     }
     fclose($fp);
     return true;
 }