Forráskód Böngészése

Se agrega sleep de 2 segundos cada 250 envíos.

Maximiliano Schvindt 7 éve
szülő
commit
6d988fa972
1 módosított fájl, 13 hozzáadás és 0 törlés
  1. 13 0
      Services/StatsD.php

+ 13 - 0
Services/StatsD.php

@@ -125,12 +125,16 @@ class StatsD
         } else {
             $sampledData = $data;
         }
+        
+        $sampledData = $data;
 
         if (empty($sampledData)) {
             return;
         }
 
         // Wrap this in a try/catch - failures in any of this should be silently ignored
+        $count = 1;
+        // print_r("Total: ".count($sampledData).PHP_EOL);
         try {
             $host = $config->getConfig("statsd.host");
             $port = $config->getConfig("statsd.port");
@@ -138,11 +142,20 @@ class StatsD
             if (!$fp) {
                 return;
             }
+            $count_send = 0;
             foreach ($sampledData as $stat => $value) {
+                // print_r("$count - $stat:$value".PHP_EOL);
+                $count++;
                 fwrite($fp, "$stat:$value");
+                $count_send++;
+                if($count_send > 250) {
+                    sleep(2);
+                    $count_send = 0;
+                }
             }
             fclose($fp);
         } catch (Exception $e) {
+            // print_r($e->getMessage());
             
         }
     }