PHPackages                             islenbo/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. islenbo/cachetool

ActiveLibrary[Caching](/categories/caching)

islenbo/cachetool
=================

Manage your OPcache &amp; APCu cache through the CLI

6.5.0(4y ago)06MITPHPPHP ^7.3|^8.0

Since Sep 22Pushed 4y agoCompare

[ Source](https://github.com/islenbo/cachetool)[ Packagist](https://packagist.org/packages/islenbo/cachetool)[ GitHub Sponsors](https://github.com/gordalina)[ RSS](/packages/islenbo-cachetool/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (13)Versions (73)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)[![Coverage Status](https://camo.githubusercontent.com/9550247fce52d2b311f286c3b817702e5eba2cac11784d10d71921b1b8be7af9/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f676f7264616c696e612f6361636865746f6f6c2f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/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 6.x works with PHP `>=7.3`
- 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 -sLO https://github.com/gordalina/cachetool/releases/latest/download/cachetool.phar
chmod +x cachetool.phar
```

You can alternatively download a compressed phar by using the URLs below.

```
# if your php installation has the zlib extension enabled
https://github.com/gordalina/cachetool/releases/latest/download/cachetool.phar.gz

# if your php installation has the bzip2 extension enabled
https://github.com/gordalina/cachetool/releases/latest/download/cachetool.phar.bz2
```

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

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

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

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

Usage
-----

[](#usage)

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
```

- Using SymfonyHttpClient

```
php cachetool.phar opcache:status --web=SymfonyHttpClient --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
```

Usage via Docker
----------------

[](#usage-via-docker)

The great folks at @sbitio, namely @NITEMAN and @jonhattan wrote a docker image that you can invoke to run CacheTool. The images are hosted in

This is an example run with the `web` adapter:

```
APPDIR="/var/www/example.com"
DOCROOT="/var/www/example.com/current/web"
URL="http://example.com"
docker run --rm -v $APPDIR:$APPDIR -w $DOCROOT sbitio/cachetool cachetool --web --web-url=$URL [options] [arguments]
```

Read more on their project page:

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.

You can pass a `--config ` option to the application or it will choose to load a file automaically.

The file must be named `.cachetool.yml` or `.cachetool.yaml`. 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` or `/etc/cachetool.yaml` 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
```

Example for the web adapter:

```
adapter: web
webClient: SymfonyHttpClient # defaults to FileGetContents
webUrl: http://example.com
webPath: /var/www/example.com/current/web
webBasicAuth: user:password
```

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. This directory should also be readable by the web user running php-fpm/apache.

SELinux
-------

[](#selinux)

To have cachetool working with SELinux [read this comment by @driskell](https://github.com/gordalina/cachetool/issues/9#issuecomment-742669509).

License
-------

[](#license)

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

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community19

Small or concentrated contributor base

Maturity83

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 83.6% 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 ~34 days

Recently: every ~7 days

Total

72

Last Release

1803d ago

Major Versions

1.x-dev → 3.0.02017-10-07

3.2.1 → 4.0.02018-07-17

4.x-dev → 5.0.02020-03-29

3.2.2 → 5.1.12020-06-24

5.x-dev → 6.0.02020-12-12

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.0.0PHP ^7.3|^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/cb6de3588c3fea8332ae3672a962243f6015c1c7819d64084fcf485d7423d6b2?d=identicon)[islenbo](/maintainers/islenbo)

---

Top Contributors

[![gordalina](https://avatars.githubusercontent.com/u/787913?v=4)](https://github.com/gordalina "gordalina (332 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)")[![nlemoine](https://avatars.githubusercontent.com/u/2526939?v=4)](https://github.com/nlemoine "nlemoine (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)")[![islenbo](https://avatars.githubusercontent.com/u/5944288?v=4)](https://github.com/islenbo "islenbo (2 commits)")[![brandung-sjorek](https://avatars.githubusercontent.com/u/38257959?v=4)](https://github.com/brandung-sjorek "brandung-sjorek (2 commits)")[![bangpound](https://avatars.githubusercontent.com/u/6731?v=4)](https://github.com/bangpound "bangpound (2 commits)")[![jorissteyn](https://avatars.githubusercontent.com/u/448056?v=4)](https://github.com/jorissteyn "jorissteyn (1 commits)")[![marvinhinz](https://avatars.githubusercontent.com/u/35603466?v=4)](https://github.com/marvinhinz "marvinhinz (1 commits)")[![plandolt](https://avatars.githubusercontent.com/u/922919?v=4)](https://github.com/plandolt "plandolt (1 commits)")[![rayderua](https://avatars.githubusercontent.com/u/10817299?v=4)](https://github.com/rayderua "rayderua (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)")[![vigneshgurusamy](https://avatars.githubusercontent.com/u/6076800?v=4)](https://github.com/vigneshgurusamy "vigneshgurusamy (1 commits)")[![dizda](https://avatars.githubusercontent.com/u/1245245?v=4)](https://github.com/dizda "dizda (1 commits)")

---

Tags

cachefastcgiapcuopcodeOpcachefpm

###  Code Quality

TestsPHPUnit

### Embed Badge

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

```
[![Health](https://phpackages.com/badges/islenbo-cachetool/health.svg)](https://phpackages.com/packages/islenbo-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.7k509.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)[sulu/sulu

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

1.3k1.3M152](/packages/sulu-sulu)[contao/core-bundle

Contao Open Source CMS

1231.6M2.4k](/packages/contao-core-bundle)

PHPackages © 2026

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