PHPackages                             promphp/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. [Caching](/categories/caching)
4. /
5. promphp/prometheus\_client\_php

ActiveLibrary[Caching](/categories/caching)

promphp/prometheus\_client\_php
===============================

Prometheus instrumentation library for PHP applications.

v2.15.0(1mo ago)54626.8M—9.1%108[40 issues](https://github.com/PromPHP/prometheus_client_php/issues)[17 PRs](https://github.com/PromPHP/prometheus_client_php/pulls)20Apache-2.0PHPPHP ^8.2CI passing

Since Jun 24Pushed 2w ago4 watchersCompare

[ Source](https://github.com/PromPHP/prometheus_client_php)[ Packagist](https://packagist.org/packages/promphp/prometheus_client_php)[ RSS](/packages/promphp-prometheus-client-php/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (17)Versions (52)Used By (20)

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

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

[![Tests](https://github.com/promphp/prometheus_client_php/workflows/Tests/badge.svg)](https://github.com/promphp/prometheus_client_php/workflows/Tests/badge.svg)[![Slack](https://camo.githubusercontent.com/51bc401df35192c06aa74d3b2278324c9e368191b20eb36c77d6c1ab1cbc1b48/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f536c61636b2d6a6f696e253230636861742d627269676874677265656e)](https://join.slack.com/t/promphp/shared_invite/zt-iqbocinr-R809BvkEhjuC9W6RRoOofA)

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 five adapters. Redis, Predis, APC, APCng, or an in-memory adapter. While the first needs a separate binary running, the second and third just need 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 promphp/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']);

$summary = $registry->getOrRegisterSummary('test', 'some_summary', 'it observes a sliding window', ['type'], 84600, [0.01, 0.05, 0.5, 0.95, 0.99]);
$summary->observe(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 Predis storage (requires `predis/predis`):

```
$registry = new CollectorRegistry(new \Prometheus\Storage\Predis());
```

Or with an existing connection:

```
$client = new \Predis\Client(['host' => '127.0.0.1']);
$registry = new CollectorRegistry(\Prometheus\Storage\Predis::fromExistingConnection($client));
```

> **Note:** Using `Redis::setPrefix()` and `Predis::setPrefix()` share the same prefix. Using both adapters with different prefixes in the same application is not supported.

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());
```

Using the APC or APCng storage:

```
$registry = new CollectorRegistry(new APCng());
 or
$registry = new CollectorRegistry(new APC());
```

(see the `README.APCng.md` file for more details)

Using the PDO storage:

```
$registry = new CollectorRegistry(new \PDO('mysql:host=localhost;dbname=prometheus', 'username', 'password'));
 or
$registry = new CollectorRegistry(new \PDO('sqlite::memory:'));
```

### 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 0.05, 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/PromPHP/prometheus\_push\_gateway\_php](https://github.com/PromPHP/prometheus_push_gateway_php)

```
composer require promphp/prometheus_push_gateway_php

```

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

[](#development)

### Dependencies

[](#dependencies)

- PHP ^8.2 (only [supported PHP versions](https://www.php.net/supported-versions.php) are supported)
- 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=apcng vendor/bin/phpunit tests/Test/
docker-compose run phpunit env ADAPTER=redis vendor/bin/phpunit tests/Test/

```

Performance testing
-------------------

[](#performance-testing)

This currently tests the APC and APCng adapters head-to-head and reports if the APCng adapter is slower for any actions.

```
phpunit vendor/bin/phpunit tests/Test/ --group Performance

```

The test can also be run inside a container.

```
docker-compose up
docker-compose run phpunit vendor/bin/phpunit tests/Test/ --group Performance

```

###  Health Score

78

—

ExcellentBetter than 100% of packages

Maintenance92

Actively maintained with recent releases

Popularity71

Solid adoption and visibility

Community46

Growing community involvement

Maturity89

Battle-tested with a long release history

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

Recently: every ~119 days

Total

46

Last Release

55d ago

Major Versions

v0.9.1 → v1.0.02019-07-22

v1.0.3 → v2.0.02020-09-22

PHP version history (8 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

v2.2.0PHP ^7.2|^8.0

v2.14.0PHP ^7.4|^8.0

v2.15.0PHP ^8.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)")[![LKaemmerling](https://avatars.githubusercontent.com/u/4281581?v=4)](https://github.com/LKaemmerling "LKaemmerling (63 commits)")[![NoelDavies](https://avatars.githubusercontent.com/u/572911?v=4)](https://github.com/NoelDavies "NoelDavies (14 commits)")[![simPod](https://avatars.githubusercontent.com/u/327717?v=4)](https://github.com/simPod "simPod (11 commits)")[![rdohms](https://avatars.githubusercontent.com/u/94331?v=4)](https://github.com/rdohms "rdohms (10 commits)")[![martinssipenko](https://avatars.githubusercontent.com/u/598744?v=4)](https://github.com/martinssipenko "martinssipenko (6 commits)")[![TobiasBengtsson](https://avatars.githubusercontent.com/u/12772476?v=4)](https://github.com/TobiasBengtsson "TobiasBengtsson (4 commits)")[![pluk77](https://avatars.githubusercontent.com/u/524179?v=4)](https://github.com/pluk77 "pluk77 (3 commits)")[![thedeacon](https://avatars.githubusercontent.com/u/4561401?v=4)](https://github.com/thedeacon "thedeacon (3 commits)")[![mps-sepetrov](https://avatars.githubusercontent.com/u/24416480?v=4)](https://github.com/mps-sepetrov "mps-sepetrov (3 commits)")[![encero](https://avatars.githubusercontent.com/u/1345022?v=4)](https://github.com/encero "encero (3 commits)")[![buffcode](https://avatars.githubusercontent.com/u/2863518?v=4)](https://github.com/buffcode "buffcode (3 commits)")[![mp3000mp](https://avatars.githubusercontent.com/u/54006012?v=4)](https://github.com/mp3000mp "mp3000mp (2 commits)")[![DeyV](https://avatars.githubusercontent.com/u/311626?v=4)](https://github.com/DeyV "DeyV (2 commits)")[![lianatech-matias-ylipelto](https://avatars.githubusercontent.com/u/129368437?v=4)](https://github.com/lianatech-matias-ylipelto "lianatech-matias-ylipelto (2 commits)")[![carusogabriel](https://avatars.githubusercontent.com/u/16328050?v=4)](https://github.com/carusogabriel "carusogabriel (2 commits)")[![SevaWeb011](https://avatars.githubusercontent.com/u/49000654?v=4)](https://github.com/SevaWeb011 "SevaWeb011 (2 commits)")[![ttk](https://avatars.githubusercontent.com/u/1742711?v=4)](https://github.com/ttk "ttk (1 commits)")[![2646298](https://avatars.githubusercontent.com/u/115662149?v=4)](https://github.com/2646298 "2646298 (1 commits)")

---

Tags

apcuhacktoberfestmetricsphpprometheusprometheus-client-libraryredis

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[react/cache

Async, Promise-based cache interface for ReactPHP

444112.4M40](/packages/react-cache)[wp-media/wp-rocket

Performance optimization plugin for WordPress

7431.3M3](/packages/wp-media-wp-rocket)[illuminate/cache

The Illuminate Cache package.

12835.6M1.4k](/packages/illuminate-cache)[colinmollenhour/php-redis-session-abstract

A Redis-based session handler with optimistic locking

6325.6M14](/packages/colinmollenhour-php-redis-session-abstract)[cheprasov/php-redis-client

Php client for Redis. It is a fast, fully-functional and user-friendly client for Redis, optimized for performance. RedisClient supports the latest versions of Redis starting from 2.6 to 6.0

1281.2M21](/packages/cheprasov-php-redis-client)[amphp/redis

Efficient asynchronous communication with Redis servers, enabling scalable and responsive data storage and retrieval.

165634.7k44](/packages/amphp-redis)

PHPackages © 2026

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