PHPackages                             lkaemmerling/prometheus\_client\_php - 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. [Logging &amp; Monitoring](/categories/logging)
4. /
5. lkaemmerling/prometheus\_client\_php

Abandoned → [promphp/prometheus\_client\_php](/?search=promphp%2Fprometheus_client_php)ArchivedLibrary[Logging &amp; Monitoring](/categories/logging)

lkaemmerling/prometheus\_client\_php
====================================

Prometheus instrumentation library for PHP applications.

v2.0.0(5y ago)312.9k1[2 issues](https://github.com/LKaemmerling/prometheus_client_php/issues)Apache-2.0PHPPHP ^7.2

Since Jun 24Pushed 5y agoCompare

[ Source](https://github.com/LKaemmerling/prometheus_client_php)[ Packagist](https://packagist.org/packages/lkaemmerling/prometheus_client_php)[ RSS](/packages/lkaemmerling-prometheus-client-php/feed)WikiDiscussions master Synced today

READMEChangelog (2)Dependencies (4)Versions (24)Used By (0)

A prometheus client library written in PHP
==========================================

[](#a-prometheus-client-library-written-in-php)

[![Tests](https://github.com/lkaemmerling/prometheus_client_php/workflows/Tests/badge.svg)](https://github.com/lkaemmerling/prometheus_client_php/workflows/Tests/badge.svg)

---

**The repository was moved to [https://github.com/PromPHP/prometheus\_client\_php](https://github.com/PromPHP/prometheus_client_php), the further development will take place there.**

---

This library uses Redis or APCu to do the client side aggregation. If using Redis, we recommend running a local Redis instance next to your PHP workers.

How does it work?
-----------------

[](#how-does-it-work)

Usually PHP worker processes don't share any state. You can pick from three adapters. Redis, APC or an in memory adapter. While the first needs a separate binary running, the second just needs the [APC](https://pecl.php.net/package/APCU) extension to be installed. If you don't need persistent metrics between requests (e.g. a long running cron job or script) the in memory adapter might be suitable to use.

Installation
------------

[](#installation)

Add as [Composer](https://getcomposer.org/) dependency:

```
composer require lkaemmerling/prometheus_client_php
```

Usage
-----

[](#usage)

A simple counter:

```
\Prometheus\CollectorRegistry::getDefault()
    ->getOrRegisterCounter('', 'some_quick_counter', 'just a quick measurement')
    ->inc();
```

Write some enhanced metrics:

```
$registry = \Prometheus\CollectorRegistry::getDefault();

$counter = $registry->getOrRegisterCounter('test', 'some_counter', 'it increases', ['type']);
$counter->incBy(3, ['blue']);

$gauge = $registry->getOrRegisterGauge('test', 'some_gauge', 'it sets', ['type']);
$gauge->set(2.5, ['blue']);

$histogram = $registry->getOrRegisterHistogram('test', 'some_histogram', 'it observes', ['type'], [0.1, 1, 2, 3.5, 4, 5, 6, 7, 8, 9]);
$histogram->observe(3.5, ['blue']);
```

Manually register and retrieve metrics (these steps are combined in the `getOrRegister...` methods):

```
$registry = \Prometheus\CollectorRegistry::getDefault();

$counterA = $registry->registerCounter('test', 'some_counter', 'it increases', ['type']);
$counterA->incBy(3, ['blue']);

// once a metric is registered, it can be retrieved using e.g. getCounter:
$counterB = $registry->getCounter('test', 'some_counter')
$counterB->incBy(2, ['red']);
```

Expose the metrics:

```
$registry = \Prometheus\CollectorRegistry::getDefault();

$renderer = new RenderTextFormat();
$result = $renderer->render($registry->getMetricFamilySamples());

header('Content-type: ' . RenderTextFormat::MIME_TYPE);
echo $result;
```

Change the Redis options (the example shows the defaults):

```
\Prometheus\Storage\Redis::setDefaultOptions(
    [
        'host' => '127.0.0.1',
        'port' => 6379,
        'password' => null,
        'timeout' => 0.1, // in seconds
        'read_timeout' => '10', // in seconds
        'persistent_connections' => false
    ]
);
```

Using the InMemory storage:

```
$registry = new CollectorRegistry(new InMemory());

$counter = $registry->registerCounter('test', 'some_counter', 'it increases', ['type']);
$counter->incBy(3, ['blue']);

$renderer = new RenderTextFormat();
$result = $renderer->render($registry->getMetricFamilySamples());
```

### Advanced Usage

[](#advanced-usage)

#### Advanced Histogram Usage

[](#advanced-histogram-usage)

On passing an empty array for the bucket parameter on instantiation, a set of default buckets will be used instead. Whilst this is a good base for a typical web application, there is named constructor to assist in the generation of exponential / geometric buckets.

Eg:

```
Histogram::exponentialBuckets(0.05, 1.5, 10);

```

This will start your buckets with a value of 1.5, grow them by a factor of 1.5 per bucket across a set of 10 buckets.

Also look at the [examples](examples).

#### PushGateway Support

[](#pushgateway-support)

As of Version 2.0.0 this library doesn't support the Prometheus PushGateway anymore because we want to have this package as small als possible. If you need Prometheus PushGateway support, you could use the companion library: [https://github.com/LKaemmerling/prometheus\_push\_gateway\_php](https://github.com/LKaemmerling/prometheus_push_gateway_php)

```
composer require lkaemmerling/prometheus_push_gateway_php

```

Development
-----------

[](#development)

### Dependencies

[](#dependencies)

- PHP ^7.2
- PHP Redis extension
- PHP APCu extension
- [Composer](https://getcomposer.org/doc/00-intro.md#installation-linux-unix-osx)
- Redis

Start a Redis instance:

```
docker-compose up Redis

```

Run the tests:

```
composer install

# when Redis is not listening on localhost:
# export REDIS_HOST=192.168.59.100
./vendor/bin/phpunit

```

Black box testing
-----------------

[](#black-box-testing)

Just start the nginx, fpm &amp; Redis setup with docker-compose:

```
docker-compose up

```

Pick the adapter you want to test.

```
docker-compose run phpunit env ADAPTER=apc vendor/bin/phpunit tests/Test/
docker-compose run phpunit env ADAPTER=redis vendor/bin/phpunit tests/Test/

```

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance7

Infrequent updates — may be unmaintained

Popularity23

Limited adoption so far

Community18

Small or concentrated contributor base

Maturity68

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

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 ~77 days

Recently: every ~262 days

Total

21

Last Release

2056d ago

Major Versions

v0.9.1 → v1.0.02019-07-22

v1.0.3 → v2.0.02020-09-22

PHP version history (5 changes)v0.1.0PHP &gt;=5.6.0

v0.2.0PHP &gt;=5.3.3

v0.6.0PHP &gt;=5.6.3

v1.0.0PHP ^7.1

v1.0.3PHP ^7.2

### Community

Maintainers

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

---

Top Contributors

[![schnipseljagd](https://avatars.githubusercontent.com/u/289073?v=4)](https://github.com/schnipseljagd "schnipseljagd (110 commits)")[![bracki](https://avatars.githubusercontent.com/u/49786?v=4)](https://github.com/bracki "bracki (98 commits)")[![NoelDavies](https://avatars.githubusercontent.com/u/572911?v=4)](https://github.com/NoelDavies "NoelDavies (14 commits)")[![LKaemmerling](https://avatars.githubusercontent.com/u/4281581?v=4)](https://github.com/LKaemmerling "LKaemmerling (8 commits)")[![martinssipenko](https://avatars.githubusercontent.com/u/598744?v=4)](https://github.com/martinssipenko "martinssipenko (6 commits)")[![buffcode](https://avatars.githubusercontent.com/u/2863518?v=4)](https://github.com/buffcode "buffcode (3 commits)")[![mps-sepetrov](https://avatars.githubusercontent.com/u/24416480?v=4)](https://github.com/mps-sepetrov "mps-sepetrov (3 commits)")[![rdohms](https://avatars.githubusercontent.com/u/94331?v=4)](https://github.com/rdohms "rdohms (2 commits)")[![carusogabriel](https://avatars.githubusercontent.com/u/16328050?v=4)](https://github.com/carusogabriel "carusogabriel (2 commits)")[![DeyV](https://avatars.githubusercontent.com/u/311626?v=4)](https://github.com/DeyV "DeyV (2 commits)")[![simPod](https://avatars.githubusercontent.com/u/327717?v=4)](https://github.com/simPod "simPod (1 commits)")[![bvisness](https://avatars.githubusercontent.com/u/4707402?v=4)](https://github.com/bvisness "bvisness (1 commits)")[![crazycodr](https://avatars.githubusercontent.com/u/4398521?v=4)](https://github.com/crazycodr "crazycodr (1 commits)")[![fbhdk](https://avatars.githubusercontent.com/u/10439895?v=4)](https://github.com/fbhdk "fbhdk (1 commits)")[![glensc](https://avatars.githubusercontent.com/u/199095?v=4)](https://github.com/glensc "glensc (1 commits)")[![Gounlaf](https://avatars.githubusercontent.com/u/236413?v=4)](https://github.com/Gounlaf "Gounlaf (1 commits)")[![kswzr](https://avatars.githubusercontent.com/u/31246037?v=4)](https://github.com/kswzr "kswzr (1 commits)")[![oraoto](https://avatars.githubusercontent.com/u/24709398?v=4)](https://github.com/oraoto "oraoto (1 commits)")[![seiffert](https://avatars.githubusercontent.com/u/1111118?v=4)](https://github.com/seiffert "seiffert (1 commits)")[![1player](https://avatars.githubusercontent.com/u/690120?v=4)](https://github.com/1player "1player (1 commits)")

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/lkaemmerling-prometheus-client-php/health.svg)

```
[![Health](https://phpackages.com/badges/lkaemmerling-prometheus-client-php/health.svg)](https://phpackages.com/packages/lkaemmerling-prometheus-client-php)
```

###  Alternatives

[psr/log

Common interface for logging libraries

10.4k1.2B9.2k](/packages/psr-log)[itsgoingd/clockwork

php dev tools in your browser

5.9k27.6M94](/packages/itsgoingd-clockwork)[graylog2/gelf-php

A php implementation to send log-messages to a GELF compatible backend like Graylog2.

41838.2M138](/packages/graylog2-gelf-php)[bugsnag/bugsnag-psr-logger

Official Bugsnag PHP PSR Logger.

32132.5M2](/packages/bugsnag-bugsnag-psr-logger)[consolidation/log

Improved Psr-3 / Psr\\Log logger based on Symfony Console components.

15462.2M7](/packages/consolidation-log)[datadog/php-datadogstatsd

An extremely simple PHP datadogstatsd client

19124.6M15](/packages/datadog-php-datadogstatsd)

PHPackages © 2026

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