PHPackages                             innmind/homeostasis - 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. innmind/homeostasis

AbandonedArchivedLibrary

innmind/homeostasis
===================

App health regulator

4.1.0(5y ago)04222MITPHPPHP ~7.4|~8.0CI failing

Since Jun 25Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/Innmind/Homeostasis)[ Packagist](https://packagist.org/packages/innmind/homeostasis)[ Docs](http://github.com/Innmind/Homeostasis)[ RSS](/packages/innmind-homeostasis/feed)WikiDiscussions develop Synced 2mo ago

READMEChangelogDependencies (11)Versions (15)Used By (2)

Homeostasis
===========

[](#homeostasis)

[![Build Status](https://github.com/Innmind/Homeostasis/workflows/CI/badge.svg?branch=master)](https://github.com/Innmind/Homeostasis/actions?query=workflow%3ACI)[![codecov](https://camo.githubusercontent.com/1e419fb8a49f4356f3e77ae937db30e68fac7e0bbbe12e50d6416551e36f39e4/68747470733a2f2f636f6465636f762e696f2f67682f496e6e6d696e642f486f6d656f7374617369732f6272616e63682f646576656c6f702f67726170682f62616467652e737667)](https://codecov.io/gh/Innmind/Homeostasis)[![Type Coverage](https://camo.githubusercontent.com/ef14bc2c3882094ec4262bb3baa9a46050db81afb44e364ca94a2e70a13268f8/68747470733a2f2f73686570686572642e6465762f6769746875622f496e6e6d696e642f486f6d656f7374617369732f636f7665726167652e737667)](https://shepherd.dev/github/Innmind/Homeostasis)

This lib is a mechanism to collect indicators from various sensors of your app (cpu usage, errors in logs, ...) and determine what action to take depending on the health of the system. For example if the app takes too much cpu for too long you should reduce the number of processes handled by the server.

In essence the process is always like this: `collect sensor values => determine strategy => call actuators`.

**Note**: no actuators is implemented in this library because these are application specific so it's up to you to know how to regulate your app.

Usage
-----

[](#usage)

```
use function Innmind\Homeostasis\bootstrap;
use Innmind\Homeostasis\{
    Factor,
    Factor\Cpu,
    Factor\Log,
    Sensor\Measure\Weight,
};
use Innmind\OperatingSystem\Factory;
use Innmind\Url\Path;
use Innmind\Math\{
    Polynom\Polynom,
    Algebra\Integer
    Algebra\Number\Number,
};
use Innmind\LogReader\{
    Reader\OnDemand,
    Log as LogLine,
};
use Innmind\Immutable\Set;
use Psr\Log\LogLevel;

$os = Factory::build();
$clock = $os->clock();
$homeostasis = bootstrap(
    Set::of(
        Factor::class,
        new Cpu(
            $clock,
            $os->status(),
            new Weight(new Number(0.5)),
            (new Polynom)->withDegree(new Integer(1), new Integer(1))
        ),
        new Log(
            $clock,
            new OnDemand(new Symfony($clock)),
            $os->filesystem()->mount(Path::of('var/logs')),
            new Weight(new Number(0.5)),
            (new Polynom)->withDegree(new Integer(1), new Integer(1)),
            static function(LogLine $line): bool {
                return $line->attributes()->contains('level') &&
                    $line->attributes()->get('level')->value() === LogLevel::CRITICAL;
            },
            'symfony',
        ),
    ),
    /*you need to implement the Actuator interface*/,
    $os->filesystem()->mount(Path::of('some/path/to/store/states')),
    $clock,
);

$modulateStateHistory = $homeostasis['modulate_state_history'](
    $os->filesystem()->mount(Path::of('some/path/to/store/actions')),
);

$regulate = $modulateStateHistory(
    $homeostasis['regulator'],
);

$regulate();
```

Above we defined a regulator that collects values from the cpu usage and the errors from the symfony logs. Each sensor is given the same importance/weight.

A sensor must return a value between `0` and `1`, `0` means there is not enough activity and `1` means there's too much. So the obvious goal is that the overall value tends toward `0.5`. But as for each sensor the way to calculate this value is different and non linear, you an specify a polynom to modulate this. In the example above we specified a linear polynom for both cpu and logs but you should change those as *not enough errors* in the logs makes no sense; polynoms should look something like this:

```
1 |                      /
  |                     /
  |                    /
  |     ______________/      Means that between 20% and 80% of cpu usage you're good
  |    /                     otherwise there's not enough or too much activity
  |   /
  |  /
  |_/_ _ _ _ _ _ _ _ _ _ _
 0           CPU          1

```

```
1 |  /--------------------
  | /
  |/
  |
  |                          As soon there are errors in the logs you're in alert
  |
  |
  |_ _ _ _ _ _ _ _ _ _ _ _
 0           LOGS         1

```

Finally, the `ModulateStateHistory` wrap is here to erase part of the history otherwise the system would have a hard time to find the tendency in the activity.

###  Health Score

42

—

FairBetter than 90% of packages

Maintenance56

Moderate activity, may be stable

Popularity12

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity76

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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 ~110 days

Recently: every ~273 days

Total

13

Last Release

1915d ago

Major Versions

1.1.1 → 2.0.02017-10-07

2.4.0 → 3.0.02019-02-24

3.0.0 → 4.0.02020-03-08

PHP version history (4 changes)1.0.0PHP ~7.1

2.2.0PHP ~7.2

4.0.0PHP ~7.4

4.1.0PHP ~7.4|~8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/851425?v=4)[Baptiste Langlade](/maintainers/Baptouuuu)[@Baptouuuu](https://github.com/Baptouuuu)

---

Top Contributors

[![Baptouuuu](https://avatars.githubusercontent.com/u/851425?v=4)](https://github.com/Baptouuuu "Baptouuuu (84 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

![Health badge](/badges/innmind-homeostasis/health.svg)

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

PHPackages © 2026

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