PHPackages                             stevencorona/opcache-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. stevencorona/opcache-json

ActiveLibrary

stevencorona/opcache-json
=========================

Library that grabs some critical stats from Zend Opcache and outputs to JSON for monitoring and alerting. Can also output to statsd sink.

v1.0.0(12y ago)117271.7k↑18.6%6MITPHPPHP &gt;=5.5.0

Since Mar 28Pushed 9y ago5 watchersCompare

[ Source](https://github.com/stevencorona/opcache-json)[ Packagist](https://packagist.org/packages/stevencorona/opcache-json)[ RSS](/packages/stevencorona-opcache-json/feed)WikiDiscussions master Synced 1mo ago

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

opcache-json
============

[](#opcache-json)

[![](https://camo.githubusercontent.com/060cd6eb7e283192b9ad784ffa03f5d396bedd5ba5327933ef570beeab42b64b/68747470733a2f2f7472617669732d63692e6f72672f73746576656e636f726f6e612f6f7063616368652d6a736f6e2e737667)](https://travis-ci.org/stevencorona/opcache-json)

PHP 5.5 is awesome. It's fast, more modern, and has a bunch of great features. One of those new, awesome features is that it gets bundled with Zend Opcache by default— no more APC! Hooray!

But this win brings some new burden. Zend Opcache has a TON of configuration settings and monitoring them is not that easy. The default output is a little bit clunky and wasn't really designed with modern devops in mind.

Designed for Modern Devops
--------------------------

[](#designed-for-modern-devops)

This library was designed to solve that problem. It cleans up Zend Opcache's internal stats and makes it easily grabbable as JSON, which your app can choose to expose to an internal HTTP endpoint. Opcache-json also exposes this data to statsd, which you can use to view historical cache data and watch trends.

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

[](#getting-started)

The best way to install it is to use Composer and add the following to your project's `composer.json` file:

```
{
    "require": {
        "stevencorona/opcache-json": "*"
    }
}
```

Basic Usage
-----------

[](#basic-usage)

```
// By default Statsd output is disabled
// $opcache = new Opcache\Status;

// Or pass in Statsd config with an array
// $opcache = new Opcache\Status(["host" => "localhost", "port" => "8125"]);

// Or configure the Statsd connection with a block
$opcache = new Opcache\Status(function() {

  $c   = new \Domnikl\Statsd\Connection\UdpSocket("127.0.0.1", "8125");
  return new \Domnikl\Statsd\Client($c, "opcache");

});

echo $opcache->status(true);
```

Statsd Output
-------------

[](#statsd-output)

Statsd output comes stock. Just configure your connection by passing a block or an array to the `Opcache\Status` constructor. The following keys are sent as gauge values to Statsd:

```
opcache.used_memory:5593056|g
opcache.free_memory:61515808|g
opcache.wasted_memory:0|g
opcache.current_wasted_percentage:0|g
opcache.num_cached_scripts:11|g
opcache.num_cached_keys:13|g
opcache.max_cached_keys:3907|g
opcache.hits:33|g
opcache.start_time:1396011952|g
opcache.last_restart_time:0|g
opcache.oom_restarts:0|g
opcache.hash_restarts:0|g
opcache.manual_restarts:0|g
opcache.misses:11|g
opcache.blacklist_misses:0|g
opcache.blacklist_miss_ratio:0|g
opcache.opcache_hit_rate:75|g

```

> **Hint:** If you have a multi-server or multi-worker environment (hint: most of us do), you probably want to add your server hostname and PHP PID to the key namespace.

Extra stats
-----------

[](#extra-stats)

If you want to send extra stats about state of Opcache, meaning one of the following metrics:

```
opcache.opcache_enabled|1|g
opcache.cache_full|0|g
opcache.restart_pending|0|g
opcache.restart_in_progress|0|g

```

You can do it by calling Opcache\\Status-&gt;send\_extra\_stats() method before calling status():

```
$opcache->send_extra_stats(array (
  'opcache_enabled'     => true,
  'cache_full'          => true,
));
```

How to run this in production
-----------------------------

[](#how-to-run-this-in-production)

The obvious, but less than elegant, way might be embed this library into your application and create an endpoint. Workable, but not so clean.

Here's a better way to do it, if you're using PHP-FPM. First, you need to install the `cgi-fcgi` utility (it's in the ubuntu package `apt-get install libfcgi0ldbl`).

Next, clone this repository to somewhere on your server. For this demo, we'll pretend that it's in `/tmp/opcache-json`. I'll also assume that your PHP-FPM pool is running on `127.0.0.1:9000`. Now, here's the trick:

```
SCRIPT_NAME=/example.php \
SCRIPT_FILENAME=/tmp/opcache-json/example.php \
REQUEST_METHOD=GET \
cgi-fcgi -bind -connect 127.0.0.1:9000

```

That will return the JSON status of your running PHP-FPM pool back to you. You can put it into a cron or something and automatically monitor it without having to pollute your running application with this code.

JSON Output
-----------

[](#json-output)

The JSON output is easy to ready and can be exposed as an internal HTTP endpoint, which can be consumed by human eyes or a monitoring systems. It's pretty straightforward— the output looks like this

[![JSON Output](https://camo.githubusercontent.com/a0c0e9f90ef186ae576d1c9f64d725b1dd618193bd62d80be4cb747579f14ee6/687474703a2f2f73746576656e636f726f6e612e6769746875622e696f2f6f7063616368652d6a736f6e2f696d616765732f73637265656e73686f742e706e67)](https://camo.githubusercontent.com/a0c0e9f90ef186ae576d1c9f64d725b1dd618193bd62d80be4cb747579f14ee6/687474703a2f2f73746576656e636f726f6e612e6769746875622e696f2f6f7063616368652d6a736f6e2f696d616765732f73637265656e73686f742e706e67)

Running the tests
-----------------

[](#running-the-tests)

You **must** enable `opcache.enable_cli` to run the tests. PHP must be built with Zend Opcache.

```
$ composer install
$ ./vendor/bin/phpunit -d opcache.enable_cli=1 tests/Opcache.php

```

The MIT License (MIT)
---------------------

[](#the-mit-license-mit)

```
Copyright (c) 2014 Steve Corona Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

```

###  Health Score

40

—

FairBetter than 88% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity49

Moderate usage in the ecosystem

Community15

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

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

4434d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6041b204b0fc53c439180f193e59e3211998412e7467a78880efab6890d3ee5c?d=identicon)[stevecorona](/maintainers/stevecorona)

---

Top Contributors

[![stevencorona](https://avatars.githubusercontent.com/u/83015?v=4)](https://github.com/stevencorona "stevencorona (32 commits)")[![adrienbrault](https://avatars.githubusercontent.com/u/611271?v=4)](https://github.com/adrienbrault "adrienbrault (1 commits)")[![sgrodzicki](https://avatars.githubusercontent.com/u/712836?v=4)](https://github.com/sgrodzicki "sgrodzicki (1 commits)")

### Embed Badge

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

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

PHPackages © 2026

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