PHPackages                             league/statsd - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. league/statsd

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

league/statsd
=============

A simple library for working with StatsD in PHP.

2.0.0(4y ago)3514.3M↓15.5%57[1 issues](https://github.com/thephpleague/statsd/issues)[3 PRs](https://github.com/thephpleague/statsd/pulls)12MITPHPPHP ^7.4 || ^8.0

Since Aug 27Pushed 3y ago13 watchersCompare

[ Source](https://github.com/thephpleague/statsd)[ Packagist](https://packagist.org/packages/league/statsd)[ Docs](https://github.com/thephpleague/statsd)[ RSS](/packages/league-statsd/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (9)Dependencies (2)Versions (11)Used By (12)

StatsD PHP Library
==================

[](#statsd-php-library)

[![Build Status](https://camo.githubusercontent.com/cdbc99a89c27f5b19d85cb8e185444937e1d46c46351c2273763356d2debb077/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f7468657068706c65616775652f7374617473642f43492e737667)](https://github.com/thephpleague/statsd/actions?query=workflow%3ACI+branch%3Amaster)[![Total Downloads](https://camo.githubusercontent.com/929fd87ce99c25b0379290fc969632000e06e3dd29234bdee271e42d9966ac13/68747470733a2f2f706f7365722e707567782e6f72672f6c65616775652f7374617473642f646f776e6c6f6164732e706e67)](https://packagist.org/packages/league/statsd)[![Latest Stable Version](https://camo.githubusercontent.com/13625aa8eca0e1e9de9f05a350a0bd50f4502d079c7e74d78bbc9184f4e5e908/68747470733a2f2f706f7365722e707567782e6f72672f6c65616775652f7374617473642f762f737461626c652e706e67)](https://packagist.org/packages/league/statsd)

A library for working with StatsD in PHP.

Install
-------

[](#install)

Via Composer:

```
composer require league/statsd
```

To use the Statsd Service Provider, you must register the provider when bootstrapping your Laravel application.

Usage
-----

[](#usage)

### Configuring

[](#configuring)

```
$statsd = new League\StatsD\Client();
$statsd->configure([
    'host' => '127.0.0.1',
    'port' => 8125,
    'namespace' => 'example'
]);
```

OR

```
$statsd1 = StatsD\Client::instance('server1')->configure([...]);
$statsd2 = StatsD\Client::instance('server2')->configure([...]);
```

The StatsD client wait for `ini_get('default_socket_timeout')` seconds when opening the socket by default. To reduce this timeout, add `'timeout' => ` to your config.

The StatsD client will throw a `ConnectionException` if it is unable to send data to the StatsD server. You may choose to disable these exceptions and log a PHP warning instead if you wish. To do so, include the following in your config:

```
    'throwConnectionExceptions' => false

```

If omitted, this option defaults to `true`.

### Counters

[](#counters)

```
$statsd->increment('web.pageview');
$statsd->decrement('storage.remaining');
$statsd->increment([
    'first.metric',
    'second.metric'
], 2);
$statsd->increment('web.clicks', 1, 0.5);
```

### Gauges

[](#gauges)

```
$statsd->gauge('api.logged_in_users', 123456);
```

### Sets

[](#sets)

```
$userID = 23;
$statsd->set('api.unique_logins', $userID);
```

### Timers

[](#timers)

```
$statsd->timing('api.response_time', 256);
```

```
$metrics = array('api.response_time' => 256, 'api.memory' => 4096));
$statsd->timings($metrics);
```

Timing Blocks
-------------

[](#timing-blocks)

```
$statsd->time('api.dbcall', function () {
    // this code execution will be timed and recorded in ms
});
```

Tags
----

[](#tags)

***Attention!** That functionality support of tags in Datadog format!*

You may configure it for all the metrics sending by the client.

```
$statsd->configure([
    'tags' => ['some_general_tag' => 'value']
]);
```

Or you may send it for a single metric.

```
$statsd->increment('web.clicks', 1, 1, ['host' => $_SERVER['HTTP_HOST']]);
```

Framework integration
---------------------

[](#framework-integration)

Although this library will work with any PHP framework, below are a few ways to integrate it quickly with the most popular ones via included adapters.

### Laravel 4.x

[](#laravel-4x)

Find the `providers` key in your `app/config/app.php` and register the Statsd Service Provider.

```
    'providers' => [
        // ...
        'League\StatsD\Laravel\Provider\StatsdServiceProvider',
    ]
```

Find the `aliases` key in your `app/config/app.php` and add the Statsd Facade Alias.

```
    'aliases' => [
        // ...
        'Statsd' => 'League\StatsD\Laravel\Facade\StatsdFacade',
    ]
```

### Laravel 5.x

[](#laravel-5x)

If you are using Laravel `>=5.5`, statsd uses [package discovery](https://laravel.com/docs/5.5/packages#package-discovery) to automatically register the service provider and facade.

For older versions of Laravel 5, or if you disable package discovery:

Find the `providers` key in your `config/app.php` and register the Statsd Service Provider.

```
    'providers' => [
        // ...
        League\StatsD\Laravel5\Provider\StatsdServiceProvider::class,
    ]
```

Find the `aliases` key in your `app/config/app.php` and add the Statsd Facade Alias.

```
    'aliases' => [
        // ...
        'Statsd' => League\StatsD\Laravel5\Facade\StatsdFacade::class,
    ]
```

### Lumen

[](#lumen)

Register the provider in your boostrap app file `boostrap/app.php`

Add the following line in the "Register Service Providers" section at the bottom of the file.

```
$app->register(\League\StatsD\Laravel5\Provider\StatsdServiceProvider::class);
```

Copy the config file `statsd.php` manually from the directory `/vendor/league/statsd/config` to the directory `/config ` (you may need to create this directory).

Package Configuration

In your `.env` file, add the configuration:

```
STATSD_HOST=127.0.0.1
STATSD_PORT=8125
STATSD_NAMESPACE=
```

Testing
-------

[](#testing)

```
phpunit

```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](https://github.com/thephpleague/statsd/blob/master/CONTRIBUTING.md) for details.

Credits
-------

[](#credits)

- [Marc Qualie](https://github.com/marcqualie)
- [All Contributors](https://github.com/thephpleague/statsd/contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](https://github.com/thephpleague/statsd/blob/master/LICENSE) for more information.

###  Health Score

52

—

FairBetter than 96% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity63

Solid adoption and visibility

Community40

Growing community involvement

Maturity74

Established project with proven stability

 Bus Factor1

Top contributor holds 60.4% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~340 days

Recently: every ~451 days

Total

10

Last Release

1585d ago

Major Versions

1.5.0 → 2.0.02022-01-15

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/534693?v=4)[Frank de Jonge](/maintainers/frankdejonge)[@frankdejonge](https://github.com/frankdejonge)

![](https://www.gravatar.com/avatar/f5dc4e05c517501e1d77e131ebcdc366fd085e4f82db2732e3864d4ddf6368b2?d=identicon)[marcqualie](/maintainers/marcqualie)

---

Top Contributors

[![marcqualie](https://avatars.githubusercontent.com/u/101022?v=4)](https://github.com/marcqualie "marcqualie (119 commits)")[![colinodell](https://avatars.githubusercontent.com/u/202034?v=4)](https://github.com/colinodell "colinodell (16 commits)")[![aranw](https://avatars.githubusercontent.com/u/241565?v=4)](https://github.com/aranw "aranw (12 commits)")[![andreskrey](https://avatars.githubusercontent.com/u/8786949?v=4)](https://github.com/andreskrey "andreskrey (7 commits)")[![richardbenson](https://avatars.githubusercontent.com/u/98186?v=4)](https://github.com/richardbenson "richardbenson (6 commits)")[![michaelmoussa](https://avatars.githubusercontent.com/u/183833?v=4)](https://github.com/michaelmoussa "michaelmoussa (5 commits)")[![Jeroeny](https://avatars.githubusercontent.com/u/1517978?v=4)](https://github.com/Jeroeny "Jeroeny (4 commits)")[![nikkiii](https://avatars.githubusercontent.com/u/891176?v=4)](https://github.com/nikkiii "nikkiii (4 commits)")[![danalloway](https://avatars.githubusercontent.com/u/2057295?v=4)](https://github.com/danalloway "danalloway (3 commits)")[![paulredmond](https://avatars.githubusercontent.com/u/177773?v=4)](https://github.com/paulredmond "paulredmond (2 commits)")[![thbourlove](https://avatars.githubusercontent.com/u/1768066?v=4)](https://github.com/thbourlove "thbourlove (2 commits)")[![vgarvardt](https://avatars.githubusercontent.com/u/173697?v=4)](https://github.com/vgarvardt "vgarvardt (2 commits)")[![carl-boisvert](https://avatars.githubusercontent.com/u/5951811?v=4)](https://github.com/carl-boisvert "carl-boisvert (1 commits)")[![bitdeli-chef](https://avatars.githubusercontent.com/u/3092978?v=4)](https://github.com/bitdeli-chef "bitdeli-chef (1 commits)")[![nathanmac](https://avatars.githubusercontent.com/u/3205902?v=4)](https://github.com/nathanmac "nathanmac (1 commits)")[![endeveit](https://avatars.githubusercontent.com/u/197781?v=4)](https://github.com/endeveit "endeveit (1 commits)")[![elliotfehr](https://avatars.githubusercontent.com/u/5550991?v=4)](https://github.com/elliotfehr "elliotfehr (1 commits)")[![pborreli](https://avatars.githubusercontent.com/u/77759?v=4)](https://github.com/pborreli "pborreli (1 commits)")[![peter279k](https://avatars.githubusercontent.com/u/9021747?v=4)](https://github.com/peter279k "peter279k (1 commits)")[![philsturgeon](https://avatars.githubusercontent.com/u/67381?v=4)](https://github.com/philsturgeon "philsturgeon (1 commits)")

---

Tags

statsdlibrarygraphite

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/league-statsd/health.svg)

```
[![Health](https://phpackages.com/badges/league-statsd/health.svg)](https://phpackages.com/packages/league-statsd)
```

###  Alternatives

[league/iso3166

ISO 3166-1 PHP Library

70036.3M116](/packages/league-iso3166)[dekor/php-array-table

PHP Library for printing associative arrays as text table (similar to mysql terminal console)

296.6M2](/packages/dekor-php-array-table)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
