PHP

How to send metrics using PHP

Interesting PHP Metrics Libraries

Sending a metric via TCP

<?
    $conn = fsockopen("carbon.hostedgraphite.com", 2003);
    fwrite($conn, "YOUR-API-KEY.foo.php-tcp 1.2\n");
    fclose($conn);
?>

Sending a metric via UDP

<?
    $sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
    $message = "YOUR-API-KEY.foo.php-udp 1.2\n";
    socket_sendto($sock, $message, strlen($message), 0, "carbon.hostedgraphite.com", 2003);
?>

Sending a metric via UDP on Heroku

<?

     $fp = fsockopen('udp://carbon.hostedgraphite.com', 2003);
     fwrite($fp, "YOUR-API-KEY.foo.php-heroku 1.2\n");
     fclose($fp);
?>

Your API key can be found on your account home page.

Last updated