---
title: PHP OPcache
description: Monitor PHP OPcache bytecode cache system.
breadcrumbs: Docs > Integrations > PHP OPcache
---

# PHP OPcache
Supported OS Integration version1.0.0
## Overview{% #overview %}

This check monitors [PHP OPcache](https://www.php.net/manual/en/book.opcache.php) through the Datadog Agent.

## Setup{% #setup %}

Follow the instructions below to install and configure this check for an Agent running on a host. For containerized environments, see the [Autodiscovery Integration Templates](https://docs.datadoghq.com/agent/kubernetes/integrations.md) for guidance on applying these instructions.

### Installation{% #installation %}

To install the `php_opcache` check on your host:

1. Install the [developer toolkit](https://docs.datadoghq.com/developers/integrations/python.md). on any machine.

1. Run `ddev -e release build php_opcache` to build the package.

1. [Download the Datadog Agent](https://app.datadoghq.com/account/settings/agent/latest).

1. Upload the build artifact to any host with an Agent and run `datadog-agent integration install -w path/to/php_opcache/dist/<ARTIFACT_NAME>.whl`.

#### OPcache{% #opcache %}

OPcache does not expose metrics by default so this integration includes a metric exporter, located here:

```gdscript3
/opt/datadog-agent/embedded/lib/python3.8/site-packages/datadog_checks/php_opcache/assets/exporter/opcache-dd-handler.php
```

You can download the exporter from the Datadog [integrations-extras](https://github.com/DataDog/integrations-extras/blob/master/php_opcache/datadog_checks/php_opcache/assets/exporter/opcache-dd-handler.php) repository.

When configuring your Agent, reference the exporter directly by this file name, or configure an alias for it on your web server. For example, if you're using Apache, the alias in the web server configuration file would look like this:

```gdscript3
Alias /opcache-status /opt/datadog-agent/embedded/lib/python3.8/site-packages/datadog_checks/php_opcache/assets/exporter/opcache-dd-handler.php
<Location /opcache-status>
    Require all denied
    Require local
</Location>
```

### Configuration{% #configuration %}

1. Edit the `php_opcache.d/conf.yaml` file, in the `conf.d/` folder at the root of your Agent's configuration directory to start collecting your `php_opcache` performance data. See the [sample `php_opcache.d/conf.yaml` file](https://github.com/DataDog/integrations-extras/blob/master/php_opcache/datadog_checks/php_opcache/data/conf.yaml.example) for all available configuration options.
   ```
   instances
     - url: http://localhost/opcache-status
   ```
1. [Restart the Agent](https://docs.datadoghq.com/agent/guide/agent-commands.md#start-stop-and-restart-the-agent).

### Validation{% #validation %}

[Run the Agent's status subcommand](https://docs.datadoghq.com/agent/guide/agent-commands.md#agent-status-and-information) and look for `php_opcache` under the Checks section.

## Data Collected{% #data-collected %}

### Metrics{% #metrics %}

|  |
|  |
| **php\_opcache.opcache\_enabled**(gauge)                             | opcache enable flag                                |
| **php\_opcache.cache\_full**(gauge)                                  | cache full time                                    |
| **php\_opcache.restart\_pending**(gauge)                             | a restart pending                                  |
| **php\_opcache.restart\_in\_progress**(gauge)                        | restart in progress                                |
| **php\_opcache.memory\_usage.used\_memory**(gauge)                   | used memory size*Shown as byte*                    |
| **php\_opcache.memory\_usage.free\_memory**(gauge)                   | free memory*Shown as byte*                         |
| **php\_opcache.memory\_usage.wasted\_memory**(gauge)                 | wasted memory*Shown as byte*                       |
| **php\_opcache.memory\_usage.current\_wasted\_percentage**(gauge)    | current wasted percentage*Shown as percent*        |
| **php\_opcache.interned\_strings\_usage.buffer\_size**(gauge)        | interned string buffer size*Shown as byte*         |
| **php\_opcache.interned\_strings\_usage.used\_memory**(gauge)        | interned string used memory*Shown as byte*         |
| **php\_opcache.interned\_strings\_usage.free\_memory**(gauge)        | interned string free memory*Shown as byte*         |
| **php\_opcache.interned\_strings\_usage.number\_of\_strings**(gauge) | interned string number of string*Shown as byte*    |
| **php\_opcache.opcache\_statistics.num\_cached\_scripts**(gauge)     | num cached script*Shown as item*                   |
| **php\_opcache.opcache\_statistics.num\_cached\_keys**(gauge)        | num cached keys*Shown as item*                     |
| **php\_opcache.opcache\_statistics.max\_cached\_keys**(gauge)        | max cached keys*Shown as item*                     |
| **php\_opcache.opcache\_statistics.hits**(gauge)                     | cache hit*Shown as hit*                            |
| **php\_opcache.opcache\_statistics.start\_time**(gauge)              | cache start time*Shown as time*                    |
| **php\_opcache.opcache\_statistics.last\_restart\_time**(gauge)      | last restart time*Shown as time*                   |
| **php\_opcache.opcache\_statistics.oom\_restarts**(gauge)            | oom restart count*Shown as occurrence*             |
| **php\_opcache.opcache\_statistics.hash\_restarts**(gauge)           | hash restart count*Shown as occurrence*            |
| **php\_opcache.opcache\_statistics.manual\_restarts**(gauge)         | description*Shown as occurrence*                   |
| **php\_opcache.opcache\_statistics.misses**(gauge)                   | number of cache miss*Shown as miss*                |
| **php\_opcache.opcache\_statistics.blacklist\_misses**(gauge)        | number of black list misses*Shown as miss*         |
| **php\_opcache.opcache\_statistics.blacklist\_miss\_ratio**(gauge)   | percent of black list miss ratio*Shown as percent* |
| **php\_opcache.opcache\_statistics.opcache\_hit\_rate**(gauge)       | percent of hit ratio*Shown as percent*             |

### Events{% #events %}

The PHP OPcache integration does not include any events.

### Service Checks{% #service-checks %}

**php\_opcache.can\_connect**

Returns `CRITICAL` if the Agent is unable to connect to and collect metrics from the monitored OPcache instance. Returns `OK` otherwise.

*Statuses: ok, critical*

## Troubleshooting{% #troubleshooting %}

Need help? Contact [Datadog support](https://docs.datadoghq.com/help/).
