<?php for ($i = 0; $i < 5; $i++) { $n = rand(100, 300); log_value('localhost', 8464, "db-query:{$n}"); } function log_value($server, $port, $value) { $fp = fsockopen("udp://{$server}", $port, $errno, $errstr); if ($fp) { fwrite($fp, "{$value}\n"); fclose($fp); } } ?>
<?php $message = $_SERVER['argv']['1']; log_value('localhost', 8675, $message); function log_value($server, $port, $value) { $sock = fsockopen("udp://{$server}", $port, $errno, $errstr); if (!$sock) { die("Could not connect: " . $errstr); } else { fwrite($sock, "{$value}"); fclose($sock); } }
<?php log_value('localhost', 8464, "hello:1"); log_value('localhost', 8464, "world:1"); echo "ok\n"; function log_value($server, $port, $value) { $fp = fsockopen("udp://{$server}", $port, $errno, $errstr); if ($fp) { fwrite($fp, "{$value}\n"); fclose($fp); } }