PHPackages                             philiplb/phpprom - 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. philiplb/phpprom

ActiveLibrary[Logging &amp; Monitoring](/categories/logging)

philiplb/phpprom
================

PHPProm is a library to measure some performance relevant metrics and expose them for Prometheus

0.1.0(9y ago)1512.5k—4.8%3MITPHPPHP &gt;=5.5

Since Nov 20Pushed 9y ago4 watchersCompare

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

READMEChangelog (1)Dependencies (8)Versions (2)Used By (0)

PHPProm
-------

[](#phpprom)

PHPProm is a library to measure some performance relevant metrics and expose them for Prometheus.

Its goal is to offer a simple, drop in solution to start measuring but without limiting customization.

As the measurements are regulary collected by Prometheus visiting a specific endpoint, they need to be stored. PHPProm offeres support for various backends like Redis or Memcached.

[![Grafana Sample](docs/grafana.png)](docs/grafana.png)

Documentation
-------------

[](#documentation)

- [API Documentation 0.1.0](http://philiplb.github.io/PHPProm/docs/0.1.0/)

Package
-------

[](#package)

PHPProm uses [SemVer](http://semver.org/) for versioning. Currently, the API changes quickly due to be &lt; 1.0.0, so take care about notes in the changelog when upgrading.

### Stable

[](#stable)

```
"require": {
    "philiplb/phpprom": "0.1.0"
}
```

### Bleeding Edge

[](#bleeding-edge)

```
"require": {
    "philiplb/phpprom": "0.2.x-dev"
}
```

Getting Started
---------------

[](#getting-started)

Here is an example about how to quickly get started measuring a Silex application using Redis as Storage:

### Prerequisites

[](#prerequisites)

You need to have the [PHP redis extension](https://pecl.php.net/package/redis) installed.

And you need to have a Redis server up and running. Here we just assume "localhost" as host and "supersecret" as authentication password.

### Require PHPProm

[](#require-phpprom)

The PHPProm package is integrated via composer:

```
composer require "philiplb/phpprom"
```

### Setup the Silex Application

[](#setup-the-silex-application)

The first step is to create a storage object:

```
$storage = new PHPProm\Storage\Redis('localhost', 'supersecret');
```

With this, the Silex setup can be called. It returns a function to be used as metrics route which can be scraped by Prometheus:

```
$silexPrometheusSetup = new PHPProm\Integration\SilexSetup();
$metricsAction = $silexPrometheusSetup->setupAndGetMetricsRoute($app, $storage);
$app->get('/metrics', $metricsAction);
```

Integrations
------------

[](#integrations)

Integrating some Prometheus scrapable metrics should be as easy as possible. So some setup steps of frameworks are abstracted away into integrations in order to make PHPProm a drop in solution.

More integrations are to come. If you have a specific request, just drop me a line. Or make a pull request. :)

### Silex

[](#silex)

The [Silex](http://silex.sensiolabs.org/) integration measures the following metrics:

- Time spent per route as gauge
- Consumed memory per route as gauge
- How often each route has been called as counter

Each metric has the route as label "name". Wheras the slashes are replaced by underscores and the route method is prefixed. So a route like this

```
$app->get('my/great/{route}', function($route) {
	// ...
});
```

gets the label "GET\_my\_great\_{route}".

This integration requires the package ["silex/silex"](https://packagist.org/packages/silex/silex).

It is represented by the class *PHPProm\\Integration\\SilexSetup* with it's usage explained in the "Getting Started" section.

Adding more metrics is easy via the function *addAvailableMetric* of the storage instance. See the subchapter for custom integrations for a detailed explanation of the parameters.

The actual measurements are added via the according storage instance functions (see again the custom integrations subchapter). All data automatically appears within the metrics endpoint.

### Custom Integration

[](#custom-integration)

Writing a custom integration consists of three parts. First, the metrics have to be setup, second measurements needs to happen and third, a Prometheus scrapable metrics endpoint has to be offered.

First, the metrics to measure have to be added to the storage instance via the method *addAvailableMetric*:

```
$storage->addAvailableMetric(
	$metric, // the Prometheus metric name itself
	$label, // the name of the one Prometheus label to categorize the values
	$help, // a small, meaningful help text for the metric
	$type, // the Prometheus type of the metric like "gauge" or "counter"
	$defaultValue // the default value to be taken if no measurement happened yet for the metric/label combination, "Nan" for example or "0"
);
```

Now, the measurements have to happen. The storage object offers two methods for this:

- *storeMeasurement($metric, $key, $value):* to store a raw value for a metric under the given key
- *incrementMeasurement($metric, $key):* increments a counter for the metric under the given key, starts with 1 if it didn't exist before

There is a little helper class to measure time, the *PHPProm\\StopWatch*. To start the measurement, call its function *start()* and to stop and store the measurement, call the function *stop($metric, $key)*. The parameters have the same meaning as the storage function parameters.

The third part is to offer an endpoint delivering the metrics. To get the content, the class *PHPProm\\PrometheusExport* exists. It has a single public function *getExport(AbstractStorage $storage, $keys)*where the storage instance is handed in along with all expected keys. The function returns a string with all the Prometheus data to be used as response in the endpoint. It should be delivered with the "Content-Type: text/plain; version=0.0.4".

Storage Implementations
-----------------------

[](#storage-implementations)

There are several storage implementations available for the measurements so the metrics endpoint can deliver them. It is also easy to write an own one if the existing ones don't cover the use case. They are all in the namespace *PHPProm\\Storage*.

### Redis

[](#redis)

The Redis storage needs to have the [PHP redis extension](https://pecl.php.net/package/redis) installed. Its constructor takes the following parameters:

- *string $host:* the connection host
- *null|string $password:* the password for authentication, null to ignore
- *int $port:* the connection port, default 6379
- *string $prefix:* the global key prefix to use, default 'PHPProm:'
- *null|string $dbIndex:* the Redis DB index to use, null to ignore

It is very fast and offers persistence, so this one is the recommended storage implementation.

### Memcached

[](#memcached)

The Memcached storage implementation needs to have the [PHP memcached extension](http://php.net/manual/en/book.memcached.php) installed. Its constructor takes the following parameters:

- *string $host:* the connection host
- *int $port:* the connection port, default 11211
- *string $prefix:* the global key prefix to use, default 'PHPProm:'

This storage implementation is even faster then Redis, but offers no persistence and so is not recommended if there are counters measured over time for example which should not be lost.

### DBAL

[](#dbal)

The DBAL storage implementation needs to have the package "doctrine/dbal" and the prerequisites of the used driver must be fullfilled. Currently, the MySQL, PostgreSQL and SQLite drivers have been tested. But the SQL statements have been kept simple in order to be compatible with many of the DBAL supported databases. Give me a shout if you find something not working.

Its constructor takes the following parameters:

- *\\Doctrine\\DBAL\\Connection $connection:* the DBAL connection
- *string $table:* the table to use

The MySQL scheme of the table is:

```
 CREATE TABLE `phpprom` (
     `key` varchar(255) NOT NULL,
     `value` double NOT NULL,
     PRIMARY KEY (`key`)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
```

The SQLite scheme of the table is:

```
CREATE TABLE `phpprom` (
	`key`	TEXT NOT NULL UNIQUE,
	`value`	REAL NOT NULL,
	PRIMARY KEY(`key`)
);
```

The PostgreSQL scheme of the table is:

```
CREATE TABLE public.phpprom (
    key VARCHAR(255) PRIMARY KEY NOT NULL,
    value DOUBLE PRECISION NOT NULL
);
CREATE UNIQUE INDEX phpprom_key_uindex ON public.phpprom (key);
```

This one is possibly the slowest one, but offers a secure data storage and is mostly available in existing stacks.

### MongoDB

[](#mongodb)

The MongoDB storage needs to have the [PHP MongoDB driver](http://php.net/manual/en/set.mongodb.php) installed. Its constructor takes the following parameters:

- *string $host*: a mongodb:// connection URI
- *string $database*: the database to use, defaults to "phppromdb"
- *string $collection*: the collection to use, defaults to "measurements"
- *array $options*: connection string options, defaults to \[\]
- *array $driverOptions*: any driver-specific options not included in MongoDB connection spec, defaults to \[\]

This storage should be reasonable fast, offers persistence but should maybe only taken if Redis, MySQL or PostgreSQL is not available.

### Custom

[](#custom)

In case you want to store the measurements in a different backend, you can inherit your implementation from *PHPProm\\Storage\\AbstractStorage* and implement the abstract methods:

- *abstract public function storeMeasurement($metric, $key, $value):*Stores a measurement.
- *abstract public function incrementMeasurement($metric, $key):*Increments a measurement, starting with 1 if it doesn't exist yet.
- *abstract public function getMeasurements($metric, array $keys, $defaultValue = 'Nan'):*Gets all measurements.

New storage implementations would make a good pull request again. :)

Status
------

[](#status)

[![Build Status](https://camo.githubusercontent.com/adaf5737c02cda934fe2e48e53254dc0b6fd0544c834fb1becd15c0b613c0663/68747470733a2f2f7472617669732d63692e6f72672f7068696c69706c622f50485050726f6d2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/philiplb/PHPProm)[![Coverage Status](https://camo.githubusercontent.com/117c219d55a5ec5b9ecd8235a6cb266bc74c51433d97f2b4b924ffa1569fcece/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f7068696c69706c622f50485050726f6d2f62616467652e706e673f6272616e63683d6d6173746572)](https://coveralls.io/r/philiplb/PHPProm?branch=master)

[![SensioLabsInsight](https://camo.githubusercontent.com/ba84ef038888072b6bd7efca0bcafef0cde59d76074dc73303679bddeafaef35/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f65303032363938362d376135352d346139662d393038362d3533616265313931383535362f6d696e692e706e67)](https://insight.sensiolabs.com/projects/e0026986-7a55-4a9f-9086-53abe1918556)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/88b67c56f6825b2e4373337bd774fd49654720de1566b3615c2769be0ffc46be/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f7068696c69706c622f50485050726f6d2f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/philiplb/PHPProm/?branch=master)

[![Total Downloads](https://camo.githubusercontent.com/339aa2c2dbd6419d727c7d480bbbae5ffc75fbfa6cb5f8caa38bbb8a82eafd58/68747470733a2f2f706f7365722e707567782e6f72672f7068696c69706c622f70687070726f6d2f646f776e6c6f6164732e737667)](https://packagist.org/packages/philiplb/phpprom)[![Latest Stable Version](https://camo.githubusercontent.com/c24e42d59a4020185ef2187ce1486780273a6de7027c52c954a6a1bdf1608b2d/68747470733a2f2f706f7365722e707567782e6f72672f7068696c69706c622f70687070726f6d2f762f737461626c652e737667)](https://packagist.org/packages/phpprom/crudlex)[![Latest Unstable Version](https://camo.githubusercontent.com/03977fe6845e8c6814f0e51bc8fb720a96e709efab164c7a3c435fd961dc0ff7/68747470733a2f2f706f7365722e707567782e6f72672f7068696c69706c622f70687070726f6d2f762f756e737461626c652e737667)](https://packagist.org/packages/phpprom/crudlex) [![License](https://camo.githubusercontent.com/4a23a0ec1e7c9fd6b95c8cb70ab260100e7e6dfcc6a8692040829e0c38e420e5/68747470733a2f2f706f7365722e707567782e6f72672f7068696c69706c622f70687070726f6d2f6c6963656e73652e737667)](https://packagist.org/packages/philiplb/phpprom)

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity32

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 98.9% 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

Unknown

Total

1

Last Release

3466d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/01057139b178118459e3f2287f208d5a0730f1d9f2c8b9032a210936607abaff?d=identicon)[philiplb](/maintainers/philiplb)

---

Top Contributors

[![philiplb](https://avatars.githubusercontent.com/u/1672238?v=4)](https://github.com/philiplb "philiplb (93 commits)")[![dakala](https://avatars.githubusercontent.com/u/285543?v=4)](https://github.com/dakala "dakala (1 commits)")

---

Tags

silexprometheusperformance measurement

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/philiplb-phpprom/health.svg)

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

###  Alternatives

[lkaemmerling/laravel-horizon-prometheus-exporter

A small package to gain and export long time information from Laravel &amp; Horizon for Prometheus.

1602.0M](/packages/lkaemmerling-laravel-horizon-prometheus-exporter)[authbucket/oauth2-php

The standard compliant OAuth2.0 library based on the Symfony Components

82107.6k4](/packages/authbucket-oauth2-php)[worldia/instrumentation-bundle

Symfony opentelemetry auto-instrumentation: requests, commands, messenger, doctrine.

2769.8k](/packages/worldia-instrumentation-bundle)[triadev/laravel-prometheus-exporter

A laravel and lumen service provider to export metrics for prometheus.

2728.2k1](/packages/triadev-laravel-prometheus-exporter)[krenor/prometheus-client

A PHP Client for Prometheus

1020.9k](/packages/krenor-prometheus-client)[mfd/typo3-prometheus

Exports Prometheus metrics for TYPO3 instances

1010.6k](/packages/mfd-typo3-prometheus)

PHPackages © 2026

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