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

ActiveLibrary[Caching](/categories/caching)

gordalina/cachetool
===================

Manage your OPcache &amp; APCu cache through the CLI

10.0.0(7mo ago)1.8k3.7M↓10.5%157[10 issues](https://github.com/gordalina/cachetool/issues)[8 PRs](https://github.com/gordalina/cachetool/pulls)5MITPHPPHP &gt;=8.1.0CI passing

Since Sep 22Pushed 3mo ago34 watchersCompare

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

READMEChangelog (10)Dependencies (12)Versions (111)Used By (5)

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

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

[![Build Status](https://camo.githubusercontent.com/b8055439f268f8df7a9f0a3ecfb0cb868c0352e5867d17958dd5112f26a68356/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f676f7264616c696e612f6361636865746f6f6c2f63692e796d6c3f6272616e63683d6d61696e267374796c653d666c61742d737175617265)](https://github.com/gordalina/cachetool/actions)[![Coverage Status](https://camo.githubusercontent.com/e0d8e3a1496a7d0ef6c15a604bf0afa03dcb89252d8efc368e9c17e3b64aa0b9/68747470733a2f2f696d672e736869656c64732e696f2f636f766572616c6c732f6769746875622f676f7264616c696e612f6361636865746f6f6c2f6d61737465723f7374796c653d666c61742d737175617265)](https://coveralls.io/github/gordalina/cachetool?branch=master)[![Version](https://camo.githubusercontent.com/6418ffaad7ae256b73adaad1a1005d3b871f3534cbe763b8bc3a3f60a03f38e9/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f7461672f676f7264616c696e612f6361636865746f6f6c3f736f72743d73656d766572267374796c653d666c61742d737175617265)](https://github.com/gordalina/cachetool/releases)[![Downloads](https://camo.githubusercontent.com/098b7c2fddf00cfd85468429850d2b119291612c3fd443243343dbb3c398f1d0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f676f7264616c696e612f6361636865746f6f6c3f7374796c653d666c61742d737175617265)](https://packagist.org/packages/gordalina/cachetool)

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.

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

CacheTool is also packaged as a docker container available in [docker hub](https://hub.docker.com/r/gordalina/cachetool) and [github](https://github.com/gordalina/cachetool/pkgs/container/cachetool) container registries.

See below for [docker usage instructions](#usage-via-docker).

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)

Images are available in docker hub and github container registries:

- `gordalina/cachetool:latest`
- `ghcr.io/gordalina/cachetool:latest`

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 gordalina/cachetool cachetool --web --web-url=$URL [options] [arguments]
```

If the website is behind a proxy and/or load balancer you may want to ask directly the webserver instead of the public facing ip. Additionally, the webserver may be listening in another port. This is an example for running cachetool from the webserver host in such a setup:

```
DOMAIN="example.com"
PORT="8008"
APPDIR="/var/www/example.com"
DOCROOT="/var/www/example.com/current/web"
URL="http://$DOMAIN:$PORT"

docker run --rm --add-host $DOMAIN:172.17.0.1 -v $APPDIR:$APPDIR -w $DOCROOT sbitio/cachetool --web --web-url=$URL [options] [arguments]
```

Thank you to @jonhattan and @NITEMAN for the [work with docker](https://github.com/sbitio/docker-cachetool).

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');
$cache = CacheTool::factory($adapter, '/tmp');
```

You can use `apcu` and `opcache` functions

```
$cache->apcu_clear_cache();
$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/Proxy/ApcuProxy.php), [`OpcacheProxy`](https://github.com/gordalina/cachetool/blob/master/src/Proxy/OpcacheProxy.php) and [`PhpProxy`](https://github.com/gordalina/cachetool/blob/master/src/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.

Building cachetool.phar
-----------------------

[](#building-cachetoolphar)

Cachetool uses [box](https://github.com/box-project/box) to built the phar, see [box-project/installation.md](https://github.com/box-project/box/blob/main/doc/installation.md) on the best way to install it in your situation. To built run `box compile`, which will output `cachetool.phar` in the project root directory.

Testing
-------

[](#testing)

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

### Troubleshooting test failures

[](#troubleshooting-test-failures)

#### sslip.io

[](#sslipio)

Tests in `tests/Adapter/Http/FileGetContentsTest` and `tests/Adapter/Http/SymfonyHttpClientTest` rely on [sslip.io](https://sslip.io/) to resolve hostnames containing an IP to the IP contained. For this to work a nameserver from sslip.io needs to be in the DNS servers configured on the host which runs those tests, otherwise hostnames like `_.127.0.0.1.sslip.io` used for testing will not resolve. The IP addresses for the DNS servers can be found on [sslip.io](https://sslip.io), how to configure them depends on the system used to run the tests.

Version Compatibility
---------------------

[](#version-compatibility)

CacheToolPHP`9.x``>=8.1``8.x``>=8.0``7.x``>=7.3``6.x``>=7.3``5.x``>=7.2``4.x``>=7.1``3.x``>=5.5.9``2.x``>=5.5.9``1.x``>=5.3.3`License
-------

[](#license)

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

###  Health Score

71

—

ExcellentBetter than 100% of packages

Maintenance73

Regular maintenance activity

Popularity68

Solid adoption and visibility

Community40

Growing community involvement

Maturity89

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 83.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 ~38 days

Recently: every ~213 days

Total

106

Last Release

211d ago

Major Versions

7.x-dev → 8.3.02022-01-25

8.5.0 → 9.0.02022-10-20

8.5.1 → 9.0.22023-04-11

8.6.1 → 9.0.42023-06-20

9.2.1 → 10.0.02025-10-19

PHP version history (7 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

8.0.1-alpha.0PHP &gt;=8.0.0

9.0.0PHP &gt;=8.1.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/3997a8664adb54d73be1861f2c2a562024cdd80dbde7eec9578f38fb8be1bb44?d=identicon)[gordalina](/maintainers/gordalina)

---

Top Contributors

[![gordalina](https://avatars.githubusercontent.com/u/787913?v=4)](https://github.com/gordalina "gordalina (423 commits)")[![jdufresne](https://avatars.githubusercontent.com/u/347634?v=4)](https://github.com/jdufresne "jdufresne (19 commits)")[![sideshowcoder](https://avatars.githubusercontent.com/u/108488?v=4)](https://github.com/sideshowcoder "sideshowcoder (9 commits)")[![dritter](https://avatars.githubusercontent.com/u/1544760?v=4)](https://github.com/dritter "dritter (6 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)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (4 commits)")[![jrmbrgs](https://avatars.githubusercontent.com/u/1610846?v=4)](https://github.com/jrmbrgs "jrmbrgs (3 commits)")[![francoisfreitag](https://avatars.githubusercontent.com/u/2758243?v=4)](https://github.com/francoisfreitag "francoisfreitag (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)")[![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)")[![barasimumatik](https://avatars.githubusercontent.com/u/48050627?v=4)](https://github.com/barasimumatik "barasimumatik (2 commits)")[![szepeviktor](https://avatars.githubusercontent.com/u/952007?v=4)](https://github.com/szepeviktor "szepeviktor (2 commits)")[![vigneshgurusamy](https://avatars.githubusercontent.com/u/6076800?v=4)](https://github.com/vigneshgurusamy "vigneshgurusamy (1 commits)")[![Chris53897](https://avatars.githubusercontent.com/u/7104259?v=4)](https://github.com/Chris53897 "Chris53897 (1 commits)")[![duxthefux](https://avatars.githubusercontent.com/u/6758162?v=4)](https://github.com/duxthefux "duxthefux (1 commits)")

---

Tags

cachefastcgiapcuopcodeOpcachefpm

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[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)[prestashop/prestashop

PrestaShop is an Open Source e-commerce platform, committed to providing the best shopping cart experience for both merchants and customers.

9.0k15.4k](/packages/prestashop-prestashop)[shopware/core

Shopware platform is the core for all Shopware ecommerce products.

595.2M386](/packages/shopware-core)

PHPackages © 2026

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