From 0b1caf322d61378e176f2586323983c8b8943625 Mon Sep 17 00:00:00 2001 From: Saju Varghese Date: Sun, 8 Feb 2026 19:56:07 -0800 Subject: [PATCH 1/2] test: update socket timeout assertions to use float type - Change timeout parameter from int to float in test constructors - Replace assertEquals with assertSame for strict type checking - Add explicit float cast for ini_get('default_socket_timeout') --- tests/unit/Connection/TcpSocketTest.php | 8 ++++---- tests/unit/Connection/UdpSocketTest.php | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/unit/Connection/TcpSocketTest.php b/tests/unit/Connection/TcpSocketTest.php index 772f890..cfb307b 100644 --- a/tests/unit/Connection/TcpSocketTest.php +++ b/tests/unit/Connection/TcpSocketTest.php @@ -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()); } @@ -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()); } @@ -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'); } } diff --git a/tests/unit/Connection/UdpSocketTest.php b/tests/unit/Connection/UdpSocketTest.php index 7cb8a2b..b1dbe58 100644 --- a/tests/unit/Connection/UdpSocketTest.php +++ b/tests/unit/Connection/UdpSocketTest.php @@ -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()); } @@ -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()); } } From bef582235746e68720290ef2395be39d532f5d78 Mon Sep 17 00:00:00 2001 From: Saju Varghese Date: Sun, 8 Feb 2026 20:01:56 -0800 Subject: [PATCH 2/2] docs: improve README accuracy and add timeout documentation - Convert bare URL to markdown link - Update version constraint to ^3.2 - Fix grammar and typos (therefor, options) - Add Connection Timeout section with float examples - Standardize heading capitalization --- README.md | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 1b14598..112cd4e 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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" } } ``` @@ -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 +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