https://github.com/willitscale/statsd
https://github.com/willitscale/statsd
Last synced: 9 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/willitscale/statsd
- Owner: willitscale
- Created: 2026-03-24T13:33:49.000Z (3 months ago)
- Default Branch: main
- Last Pushed: 2026-03-24T13:39:28.000Z (3 months ago)
- Last Synced: 2026-03-25T17:42:32.125Z (3 months ago)
- Language: PHP
- Size: 12.7 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# statsd-php
A PHP client library for the statistics daemon ([statsd](https://github.com/etsy/statsd)) intended to send metrics from PHP applications.
[](http://travis-ci.org/domnikl/statsd-php)
## Installation
The best way to install statsd-php is to use Composer and add the following to your project's `composer.json` file:
```javascript
{
"require": {
"domnikl/statsd": "~2.0"
}
}
```
## Usage
```php
setNamespace("test");
// simple counts
$statsd->increment("foo.bar");
$statsd->decrement("foo.bar");
$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.
### [Timings](https://github.com/etsy/statsd/blob/master/docs/metric_types.md#timing)
```php
timing("foo.bar", 320);
$statsd->time("foo.bar.bla", function() {
// code to be measured goes here ...
});
// more complex timings can be handled with startTiming() and endTiming()
$statsd->startTiming("foo.bar");
// more complex code here ...
$statsd->endTiming("foo.bar");
```
### Memory profiling
```php
startMemoryProfile('memory.foo');
// some complex code goes here ...
$statsd->endMemoryProfile('memory.foo');
// report peak usage
$statsd->memory('foo.memory_peak_usage');
```
### [Gauges](https://github.com/etsy/statsd/blob/master/docs/metric_types.md#gauges)
statsd supports gauges, arbitrary values which can be recorded.
This method accepts both absolute (3) and delta (+11) values.
*NOTE:* Negative values are treated as delta values, not absolute.
```php
gauge('foobar', 3);
// Pass delta values as a string.
// Accepts both positive (+11) and negative (-4) delta values.
$statsd->gauge('foobar', '+11');
```
### [Sets](https://github.com/etsy/statsd/blob/master/docs/metric_types.md#sets)
statsd supports sets, so you can view the uniqueness of a given value.
```php
set('userId', 1234);
```
### 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.
## Authors
Original author: Dominik Liebler
Several other [contributors](https://github.com/domnikl/statsd-php/graphs/contributors) - Thank you!
## License
(The MIT License)
Copyright (c) 2016 Dominik Liebler
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.