Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ A PHP client library for the statistics daemon ([statsd](https://github.com/etsy

[![Build Status](https://github.com/slickdeals/statsd-php/workflows/Build%20statsd-php/badge.svg)](https://github.com/slickdeals/statsd-php/actions)

Originally a fork of https://github.com/domnikl/statsd-php and original author Dominik Liebler. The Slickdeals team has
taken over the project.
Originally a fork of [domnikl/statsd-php](https://github.com/domnikl/statsd-php) and original author Dominik Liebler. The Slickdeals team has taken over the project.

## Installation

Expand All @@ -14,7 +13,7 @@ The best way to install statsd-php is to use Composer and add the following to y
```javascript
{
"require": {
"slickdeals/statsd": "~3.0"
"slickdeals/statsd": "^3.2"
}
}
```
Expand All @@ -38,7 +37,22 @@ $statsd->count("foo.bar", 1000);
When establishing the connection to statsd and sending metrics, errors will be suppressed to prevent your application from crashing.

If you run statsd in TCP mode, there is also a `\Domnikl\Statsd\Connection\TcpSocket` adapter that works like the `UdpSocket` except that it throws a `\Domnikl\Statsd\Connection\TcpSocketException` if no connection could be established.
Please consider that unlike UDP, TCP is used for reliable networks and therefor exceptions (and errors) will not be suppressed in TCP mode.
Please consider that unlike UDP, TCP is used for reliable networks and therefore exceptions (and errors) will not be suppressed in TCP mode.

### Connection Timeout

Both `UdpSocket` and `TcpSocket` support configurable connection timeouts. The timeout parameter accepts float values, allowing fractional second precision:

```php
<?php
// 2.5 second timeout
$connection = new \Domnikl\Statsd\Connection\UdpSocket('localhost', 8125, 2.5);

// 500ms timeout
$connection = new \Domnikl\Statsd\Connection\TcpSocket('localhost', 8125, 0.5);
```

If no timeout is specified, the default value from `ini_get('default_socket_timeout')` is used.

### Sampling Rate

Expand Down Expand Up @@ -101,11 +115,9 @@ statsd supports sets, so you can view the uniqueness of a given value.
$statsd->set('userId', 1234);
```

### disabling sending of metrics
### Disabling Sending of Metrics

To disable sending any metrics to the statsd server, you can use the `Domnikl\Statsd\Connection\Blackhole` connection
class instead of the default socket abstraction. This may be incredibly useful for feature flags. Another options is
to use `Domnikl\Statsd\Connection\InMemory` connection class, that will collect your messages but won't actually send them.
To disable sending any metrics to the statsd server, you can use the `Domnikl\Statsd\Connection\Blackhole` connection class instead of the default socket abstraction. This may be incredibly useful for feature flags. Another option is to use `Domnikl\Statsd\Connection\InMemory` connection class, that will collect your messages but won't actually send them.

## StatsdAwareInterface

Expand Down
8 changes: 4 additions & 4 deletions tests/unit/Connection/TcpSocketTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ class TcpSocketTest extends TestCase
{
public function testInit()
{
$connection = new TcpSocket('localhost', 8125, 10, true);
$connection = new TcpSocket('localhost', 8125, 10.0, true);

$this->assertEquals('localhost', $connection->getHost());
$this->assertEquals(8125, $connection->getPort());
$this->assertEquals(10, $connection->getTimeout());
$this->assertSame(10.0, $connection->getTimeout());
$this->assertTrue($connection->isPersistent());
}

Expand All @@ -25,7 +25,7 @@ public function testInitDefaults()

$this->assertEquals('localhost', $connection->getHost());
$this->assertEquals(8125, $connection->getPort());
$this->assertEquals(ini_get('default_socket_timeout'), $connection->getTimeout());
$this->assertSame((float) ini_get('default_socket_timeout'), $connection->getTimeout());
$this->assertFalse($connection->isPersistent());
}

Expand All @@ -34,7 +34,7 @@ public function testThrowsExceptionWhenTryingToConnectToNotExistingServer()
$this->expectException(\Domnikl\Statsd\Connection\TcpSocketException::class);
$this->expectExceptionMessage('Couldn\'t connect to host "localhost:66000":');

$connection = new TcpSocket('localhost', 66000, 1);
$connection = new TcpSocket('localhost', 66000, 1.0);
$connection->send('foobar');
}
}
6 changes: 3 additions & 3 deletions tests/unit/Connection/UdpSocketTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ class UdpSocketTest extends TestCase
{
public function testInit()
{
$connection = new UdpSocket('localhost', 8125, 10, true);
$connection = new UdpSocket('localhost', 8125, 10.0, true);
$this->assertEquals('localhost', $connection->getHost());
$this->assertEquals(8125, $connection->getPort());
$this->assertEquals(10, $connection->getTimeout());
$this->assertSame(10.0, $connection->getTimeout());
$this->assertTrue($connection->isPersistent());
}

Expand All @@ -23,7 +23,7 @@ public function testInitDefaults()
$connection = new UdpSocket();
$this->assertEquals('localhost', $connection->getHost());
$this->assertEquals(8125, $connection->getPort());
$this->assertEquals(ini_get('default_socket_timeout'), $connection->getTimeout());
$this->assertSame((float) ini_get('default_socket_timeout'), $connection->getTimeout());
$this->assertFalse($connection->isPersistent());
}
}
Loading