# PHP

### Interesting PHP Metrics Libraries

* **PHP StatsD**\
  <https://github.com/domnikl/statsd-php> - A PHP StatsD client available in Composer\
  <https://github.com/seejohnrun/php-statsd> - A simple PHP StatsD client

### Sending a metric via TCP

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

### Sending a metric via UDP

```php
<?
    $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

```php
<?

     $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](https://www.hostedgraphite.com/accounts/profile/) page.
