PHPackages                             potfur/health-json - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. potfur/health-json

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

potfur/health-json
==================

Health JSON Schema implementation

43PHP

Since Dec 10Pushed 9y ago1 watchersCompare

[ Source](https://github.com/potfur/health-json)[ Packagist](https://packagist.org/packages/potfur/health-json)[ RSS](/packages/potfur-health-json/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

Health
======

[](#health)

[![Travis CI](https://camo.githubusercontent.com/666a1188a1d4a90cce814eaa67705f5270e74b59ec5c77ec13fb67c6430a2dfb/68747470733a2f2f7472617669732d63692e6f72672f706f746675722f6865616c74682d6a736f6e2e7376673f6272616e63683d6d6173746572 "Travis CI")](https://camo.githubusercontent.com/666a1188a1d4a90cce814eaa67705f5270e74b59ec5c77ec13fb67c6430a2dfb/68747470733a2f2f7472617669732d63692e6f72672f706f746675722f6865616c74682d6a736f6e2e7376673f6272616e63683d6d6173746572)

Lets say there is a service that needs to be checked periodically if is running. Simplest solution would be to *ping* main site and if it responds with `200` everything is fine.

But, in reality service can not connect to database and response is served from outdated cache. Other case would be when everything works but mailing service is unreachable.

And this is where **Health** comes on stage. **Health** is an implementation of [Health JSON Schema](healthjson.org) which standardises responses structure for monitoring endpoints.

How to use
----------

[](#how-to-use)

Create instance of `Health` where all services requiring monitoring will be registered

```
use Health\Health;
use Health\Service\CallableService;

$health = new Health(
	'some-app',  // application name
	'healthy-server.com',  // host name
	'1.2.3',  // currently deployed version
	new \DateTime('2016-12-05T12:45:11+00:00')  // deployment date
);

$health->addService(
    'database',  // service group
    new CallableService(
        'postgres', // service name
        function () use ($pdo) { $pdo->exec('SELECT 1'); }, // validating function
        true // true if service is essential
    )
);
```

When all services were registered, `Health` can create status snapshots. Such snapshot can be used to expose service health as simple *true/false* endpoint:

```
$state = $health->state();
$state->isHealthy();  // returns true if all services are working
$state->summary(); // returns array with detailed information about all registered services
```

Example
-------

[](#example)

In Symfony, for example

- `/ping` endpoint that returns 200 when essential services are working properly and 500 otherwise,
- `/health` endpoint that shows summary for all services, response status code is reflectin its health

```
class HealthController extends Controller
{
    /**
     * @Route("/ping", name="health_ping")
     */
    public function pingAction(): Response
    {
        return (new Response())->setStatusCode($this->get('health')->status()->isHealthy(true) ? 200 : 500);
    }

    /**
     * @Route("/health", name="health_summary")
     */
    public function healthAction(string $sku): Response
    {
        $status = $this->get('health')->status();

        $response = new JsonResponse();
        $response->setData($status->summary());
        $response->setStatusCode($status->isHealthy() ? 200 : 500);

        return $response;
    }
}
```

###  Health Score

20

—

LowBetter than 13% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/8addaf28c1a25afd6006377779228ee980528e4ca23793a4ab8bc426dda5018b?d=identicon)[potfur](/maintainers/potfur)

---

Top Contributors

[![potfur](https://avatars.githubusercontent.com/u/1244857?v=4)](https://github.com/potfur "potfur (3 commits)")

### Embed Badge

![Health badge](/badges/potfur-health-json/health.svg)

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

###  Alternatives

[jamesmills/laravel-timezone

Timezone storage and retrieval for Laravel

696779.9k13](/packages/jamesmills-laravel-timezone)[dotink/jin

Jsonified Ini Notation

1410.5k3](/packages/dotink-jin)

PHPackages © 2026

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