PHPackages                             duxthefux/cachetool - 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. [Caching](/categories/caching)
4. /
5. duxthefux/cachetool

ActiveLibrary[Caching](/categories/caching)

duxthefux/cachetool
===================

Manage your OPcache &amp; APCu cache through the CLI

6.1(5y ago)0704MITPHPPHP ^7.3|^8.0

Since Sep 22Pushed 5y agoCompare

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

READMEChangelog (2)Dependencies (10)Versions (62)Used By (0)

CacheTool - Manage cache in the CLI
===================================

[](#cachetool---manage-cache-in-the-cli)

[![Build Status](https://github.com/gordalina/cachetool/workflows/ci/badge.svg)](https://github.com/gordalina/cachetool/actions)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/dd83b21c2ac2256b38e7860141d3c3c1595abd852f8b87a32eeca002c1288924/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f676f7264616c696e612f6361636865746f6f6c2e737667)](https://scrutinizer-ci.com/g/gordalina/cachetool/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/25169cc7d489cc4bdc328ed39ff8a6dfd70dd83cef9d42e509bdeac92b02ac17/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f676f7264616c696e612f6361636865746f6f6c2e737667)](https://scrutinizer-ci.com/g/gordalina/cachetool/?branch=master)

CacheTool allows you to work with APCu, OPcache, and the file status cache through the CLI. It will connect to a FastCGI server (like PHP-FPM) and operate on its cache.

Why is this useful?

- Maybe you want to clear the bytecode cache without reloading php-fpm or using a web endpoint
- Maybe you want to have a cron which deals with cache invalidation
- Maybe you want to see some statistics right from the console
- And many more...

Note that, unlike APCu and Opcache, the file status cache is per-process rather than stored in shared memory. This means that running `stat:clear` against PHP-FPM will only affect whichever FPM worker responds to the request, not the whole pool. [Julien Pauli has written a post](http://blog.jpauli.tech/2014-06-30-realpath-cache-html/) with more details on how the file status cache operates.

Compatibility
-------------

[](#compatibility)

- CacheTool 5.x works with PHP `>=7.2`
- CacheTool 4.x works with PHP `>=7.1`
- CacheTool 3.x works with PHP `>=5.5.9`
- CacheTool 2.x works with PHP `>=5.5.9`
- CacheTool 1.x works with PHP `>=5.3.3`

Installation - Latest version
-----------------------------

[](#installation---latest-version)

```
curl -sO https://gordalina.github.io/cachetool/downloads/cachetool.phar
chmod +x cachetool.phar
```

Installation - old versions
---------------------------

[](#installation---old-versions)

Use tag name in the binary file name. E.g to download cachetool 3.2.1 which is compatible with PHP `>=5.5.9` use: `cachetool-3.2.1.phar`

```
curl -sO https://gordalina.github.io/cachetool/downloads/cachetool-3.2.1.phar
chmod +x cachetool-3.2.1.phar
```

Usage (as an application)
-------------------------

[](#usage-as-an-application)

CacheTool requires an adapter to connect to, it can be `cli`, `fcgi`, and `web`. The `fcgi` adapter is the most common, as it connects directly to php-fpm.

You can pass an IP address or a unix socket to the `--fcgi` adapter, or leave it blank and CacheTool will try to find the php-fpm socket for you. If it can't find it, it will default to `127.0.0.1:9000`.

- You can let CacheTool find the unix socket for you, or default to IP.

```
php cachetool.phar apcu:cache:info --fcgi
```

- You can connect to a fastcgi server using an IP address

```
php cachetool.phar apcu:cache:info --fcgi=127.0.0.1:9000
```

- You can connect to a fastcgi server using a unix socket

```
php cachetool.phar opcache:status --fcgi=/var/run/php5-fpm.sock
```

- To connect to a chrooted fastcgi server you need to set `--fcgi-chroot` and `--tmp-dir` parameters

```
php cachetool.phar opcache:status --fcgi=/var/run/php5-fpm.sock --fcgi-chroot=/path/to/chroot --tmp-dir=/path/to/chroot/tmp
```

- Using the CLI

```
php cachetool.phar opcache:status --cli
```

- Using an HTTP interface

```
php cachetool.phar opcache:status --web --web-path=/path/to/your/document/root --web-url=http://url-to-your-document.root
```

You have some useful commands that you can use

```
 apcu
  apcu:cache:clear            Clears APCu cache
  apcu:cache:info             Shows APCu user & system cache information
  apcu:cache:info:keys        Shows APCu keys cache information
  apcu:key:delete             Deletes an APCu key
  apcu:key:exists             Checks if an APCu key exists
  apcu:key:fetch              Shows the content of an APCu key
  apcu:key:store              Store an APCu key with given value
  apcu:regexp:delete          Deletes all APCu key matching a regexp
  apcu:sma:info               Show APCu shared memory allocation information
 opcache
  opcache:compile:script      Compile single script from path to the opcode cache
  opcache:compile:scripts     Compile scripts from path to the opcode cache
  opcache:configuration       Get configuration information about the cache
  opcache:invalidate:scripts  Remove scripts from the opcode cache
  opcache:reset               Resets the contents of the opcode cache
  opcache:reset:file-cache    Deletes all contents of the file cache directory
  opcache:status              Show summary information about the opcode cache
  opcache:status:scripts      Show scripts in the opcode cache
 stat
  stat:clear                  Clears the file status cache, including the realpath cache
  stat:realpath_get           Show summary information of realpath cache entries
  stat:realpath_size          Display size of realpath cache
```

Configuration File
------------------

[](#configuration-file)

You can have a configuration file with the adapter configuration, allowing you to call CacheTool without `--fcgi`, `--cli`, or `--web` option.

The file must be named `.cachetool.yml`. CacheTool will look for this file on the current directory and in any parent directory until it finds one. If the paths above fail it will try to load `/etc/cachetool.yml` configuration file.

An example of what this file might look like is:

Will connect to fastcgi at 127.0.0.1:9000

```
adapter: fastcgi
fastcgi: 127.0.0.1:9000
```

Will connect to cli (disregarding fastcgi configuration)

```
adapter: cli
fastcgi: /var/run/php5-fpm.sock
```

CacheTool writes files to the system temporary directory (given by `sys_get_temp_dir()`) but if you want to change this, for example, if your fastcgi service is run with PrivateTemp you can set it on the config file:

```
adapter: fastcgi
fastcgi: /var/run/php5-fpm.sock
temp_dir: /dev/shm/cachetool
```

You can define the supported extensions in the config file. By default, `apcu`, and `opcache` are enabled. To disable `apcu`, add this to your config file:

```
extensions: [opcache]
```

Usage (as a library)
--------------------

[](#usage-as-a-library)

Add it as a dependency

```
composer require gordalina/cachetool
```

If you want to use it in a Symfony 2.x project, require the `1.x` version

```
composer require gordalina/cachetool:~1.0
```

Create instance

```
use CacheTool\Adapter\FastCGI;
use CacheTool\CacheTool;

$adapter = new FastCGI('127.0.0.1:9000', $tempDir = '/tmp');
$cache = CacheTool::factory($adapter);
```

You can use `apcu` and `opcache` functions

```
$cache->apcu_clear_cache('both');
$cache->opcache_reset();
```

Proxies
-------

[](#proxies)

CacheTool depends on `Proxies` to provide functionality, by default when creating a CacheTool instance from the factory all proxies are enabled [`ApcuProxy`](https://github.com/gordalina/cachetool/blob/master/src/CacheTool/Proxy/ApcuProxy.php), [`OpcacheProxy`](https://github.com/gordalina/cachetool/blob/master/src/CacheTool/Proxy/OpcacheProxy.php) and [`PhpProxy`](https://github.com/gordalina/cachetool/blob/master/src/CacheTool/Proxy/PhpProxy.php), you can customize it or extend to your will like the example below:

```
use CacheTool\Adapter\FastCGI;
use CacheTool\CacheTool;
use CacheTool\Proxy;

$adapter = new FastCGI('/var/run/php5-fpm.sock');
$cache = new CacheTool();
$cache->setAdapter($adapter);
$cache->addProxy(new Proxy\ApcuProxy());
$cache->addProxy(new Proxy\PhpProxy());
```

Updating CacheTool
------------------

[](#updating-cachetool)

Running `php cachetool.phar self-update` will update a phar install with the latest version.

Testing
-------

[](#testing)

After running `composer install`, run `./vendor/bin/phpunit`

Troubleshooting
---------------

[](#troubleshooting)

> \[RuntimeException\] Error: Unable to open primary script: /dev/shm/cachetool-584743c678dbb.php (No such file or directory) Status: 404 Not Found Content-type: text/html; charset=UTF-8 No input file specified.

This means that cachetool could not write to `/dev/shm` provide a directory that cachetool can write to through `php cachetool.phar --tmp-dir=/writable/dir` or configuration.

License
-------

[](#license)

CacheTool is licensed under the MIT License - see the [LICENSE](LICENSE) for details

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community19

Small or concentrated contributor base

Maturity82

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 79.4% 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 ~41 days

Recently: every ~99 days

Total

57

Last Release

1953d ago

Major Versions

1.10.2 → 2.x-dev2016-06-15

1.x-dev → 3.0.02017-10-07

3.x-dev → 4.0.02018-07-17

4.x-dev → 5.0.02020-03-29

5.0.0 → 6.0.02020-06-04

PHP version history (5 changes)1.4.0PHP &gt;=5.3.3

2.0.0PHP &gt;=5.5.9

4.0.0PHP &gt;=7.1.0

5.0.0PHP ^7.2.0

6.1PHP ^7.3|^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/07aef729df63d7497d0d238a57692abaa22787f6b0780e39c814a49f1678be7c?d=identicon)[duxthefux](/maintainers/duxthefux)

---

Top Contributors

[![gordalina](https://avatars.githubusercontent.com/u/787913?v=4)](https://github.com/gordalina "gordalina (250 commits)")[![jdufresne](https://avatars.githubusercontent.com/u/347634?v=4)](https://github.com/jdufresne "jdufresne (19 commits)")[![fyrye](https://avatars.githubusercontent.com/u/302306?v=4)](https://github.com/fyrye "fyrye (6 commits)")[![MasonM](https://avatars.githubusercontent.com/u/651224?v=4)](https://github.com/MasonM "MasonM (4 commits)")[![jrmbrgs](https://avatars.githubusercontent.com/u/1610846?v=4)](https://github.com/jrmbrgs "jrmbrgs (3 commits)")[![MikeSorokin](https://avatars.githubusercontent.com/u/5099493?v=4)](https://github.com/MikeSorokin "MikeSorokin (3 commits)")[![duxthefux](https://avatars.githubusercontent.com/u/6758162?v=4)](https://github.com/duxthefux "duxthefux (2 commits)")[![bangpound](https://avatars.githubusercontent.com/u/6731?v=4)](https://github.com/bangpound "bangpound (2 commits)")[![brandung-sjorek](https://avatars.githubusercontent.com/u/38257959?v=4)](https://github.com/brandung-sjorek "brandung-sjorek (2 commits)")[![rusnak](https://avatars.githubusercontent.com/u/1324805?v=4)](https://github.com/rusnak "rusnak (2 commits)")[![sebastien-fauvel](https://avatars.githubusercontent.com/u/4215521?v=4)](https://github.com/sebastien-fauvel "sebastien-fauvel (2 commits)")[![jaymecd](https://avatars.githubusercontent.com/u/824109?v=4)](https://github.com/jaymecd "jaymecd (1 commits)")[![jewome62](https://avatars.githubusercontent.com/u/472429?v=4)](https://github.com/jewome62 "jewome62 (1 commits)")[![johnorourke](https://avatars.githubusercontent.com/u/2004038?v=4)](https://github.com/johnorourke "johnorourke (1 commits)")[![kornrunner](https://avatars.githubusercontent.com/u/725986?v=4)](https://github.com/kornrunner "kornrunner (1 commits)")[![plandolt](https://avatars.githubusercontent.com/u/922919?v=4)](https://github.com/plandolt "plandolt (1 commits)")[![samdark](https://avatars.githubusercontent.com/u/47294?v=4)](https://github.com/samdark "samdark (1 commits)")[![szepeviktor](https://avatars.githubusercontent.com/u/952007?v=4)](https://github.com/szepeviktor "szepeviktor (1 commits)")[![tmotyl](https://avatars.githubusercontent.com/u/515397?v=4)](https://github.com/tmotyl "tmotyl (1 commits)")[![alexislefebvre](https://avatars.githubusercontent.com/u/2071331?v=4)](https://github.com/alexislefebvre "alexislefebvre (1 commits)")

---

Tags

cachefastcgiapcuopcodeOpcachefpm

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/duxthefux-cachetool/health.svg)

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

###  Alternatives

[gordalina/cachetool

Manage your OPcache &amp; APCu cache through the CLI

1.8k3.7M5](/packages/gordalina-cachetool)[laravel/framework

The Laravel Framework.

34.6k509.9M17.0k](/packages/laravel-framework)[shopware/platform

The Shopware e-commerce core

3.3k1.5M3](/packages/shopware-platform)[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M651](/packages/sylius-sylius)[drupal/core

Drupal is an open source content management platform powering millions of websites and applications.

19462.3M1.3k](/packages/drupal-core)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.3M152](/packages/sulu-sulu)

PHPackages © 2026

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