PHPackages                             2tvenom/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. 2tvenom/prometheus\_client\_php

ActiveLibrary

2tvenom/prometheus\_client\_php
===============================

v0.9.2(7y ago)022Apache-2.0PHPPHP &gt;=5.6.3

Since Jun 24Pushed 7y ago1 watchersCompare

[ Source](https://github.com/2tvenom/prometheus_client_php)[ Packagist](https://packagist.org/packages/2tvenom/prometheus_client_php)[ RSS](/packages/2tvenom-prometheus-client-php/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (1)Dependencies (3)Versions (23)Used By (0)

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

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

[![Build Status](https://camo.githubusercontent.com/0917cadb39723bfe4eac43a7515988f1382d9c62d6bf53e77fd4fa15405d0295/68747470733a2f2f7472617669732d63692e6f72672f4a696d646f2f70726f6d6574686575735f636c69656e745f7068702e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/Jimdo/prometheus_client_php)

This library uses Redis or APCu to do the client side aggregation. If using Redis, we recommend to run 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.

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

Also look at the [examples](examples).

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

[](#development)

### Dependencies

[](#dependencies)

- PHP 5.6
- 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

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

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

Recently: every ~170 days

Total

18

Last Release

2816d ago

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

v0.2.0PHP &gt;=5.3.3

v0.6.0PHP &gt;=5.6.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/058cbd4474dac88cd398b19078fd3576faaefb47438b84c932329284eafd7a09?d=identicon)[2tvenom](/maintainers/2tvenom)

---

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 (97 commits)")[![mps-sepetrov](https://avatars.githubusercontent.com/u/24416480?v=4)](https://github.com/mps-sepetrov "mps-sepetrov (3 commits)")[![buffcode](https://avatars.githubusercontent.com/u/2863518?v=4)](https://github.com/buffcode "buffcode (3 commits)")[![2tvenom](https://avatars.githubusercontent.com/u/2022386?v=4)](https://github.com/2tvenom "2tvenom (2 commits)")[![1player](https://avatars.githubusercontent.com/u/690120?v=4)](https://github.com/1player "1player (1 commits)")[![seiffert](https://avatars.githubusercontent.com/u/1111118?v=4)](https://github.com/seiffert "seiffert (1 commits)")[![crazycodr](https://avatars.githubusercontent.com/u/4398521?v=4)](https://github.com/crazycodr "crazycodr (1 commits)")[![glensc](https://avatars.githubusercontent.com/u/199095?v=4)](https://github.com/glensc "glensc (1 commits)")[![oraoto](https://avatars.githubusercontent.com/u/24709398?v=4)](https://github.com/oraoto "oraoto (1 commits)")[![rdohms](https://avatars.githubusercontent.com/u/94331?v=4)](https://github.com/rdohms "rdohms (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[neuron-core/neuron-ai

The PHP Agentic Framework.

1.8k245.3k20](/packages/neuron-core-neuron-ai)[tencentcloud/tencentcloud-sdk-php

TencentCloudApi php sdk

3731.2M42](/packages/tencentcloud-tencentcloud-sdk-php)

PHPackages © 2026

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