<commit_before>CacheTool - Manage cache in the CLI
===================================

[![Build Status](https://travis-ci.org/gordalina/cachetool.svg?branch=master)](https://travis-ci.org/gordalina/cachetool)
[![HHVM Status](http://hhvm.h4cc.de/badge/gordalina/cachetool.svg)](http://hhvm.h4cc.de/package/gordalina/cachetool)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/gordalina/cachetool/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/gordalina/cachetool/?branch=master)
[![Code Coverage](https://scrutinizer-ci.com/g/gordalina/cachetool/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/gordalina/cachetool/?branch=master)
[![SensioLabsInsight](https://insight.sensiolabs.com/projects/595c9feb-3f4d-473a-a575-81c7e97eb672/mini.png)](https://insight.sensiolabs.com/projects/595c9feb-3f4d-473a-a575-81c7e97eb672)
[![Codacy Badge](https://www.codacy.com/project/badge/2d4176f2526d4251a51b691249c4d3e1)](https://www.codacy.com)

CacheTool allows you to work with `apc` and `opcache` through the cli.
It will connect to a fastcgi server (like php-fpm) and operate it's 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...

Installation
------------

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

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

You can connect to a automatically guessed fastcgi server (if `/var/run/php5-fpm.sock` is a file or `127.0.0.1:9000`)

```sh
$ php cachetool.phar apc:cache:info --fcgi
```

You can connect to a fastcgi server through ip

```sh
$ php cachetool.phar apc:cache:info --fcgi=127.0.0.1:9000
```

Or by socket

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

Or to the cli

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

You have some useful commands that you can you

```sh
apc
  apc:bin:dump             Get a binary dump of files and user variables
  apc:bin:load             Load a binary dump into the APC file and user variables
  apc:cache:clear          Clears APC cache (user, system or all)
  apc:cache:info           Shows APC user & system cache information
  apc:cache:info:file      Shows APC file cache information
  apc:key:delete           Deletes an APC key
  apc:key:exists           Checks if an APC key exists
  apc:key:fetch            Shows the content of an APC key
  apc:key:store            Store an APC key with given value
  apc:sma:info             Show APC shared memory allocation information
opcache
  opcache:configuration    Get configuration information about the cache
  opcache:reset            Resets the contents of the opcode cache
  opcache:status           Show summary information about the opcode cache
  opcache:status:scripts   Show scripts in the opcode cache
```

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

You can have a configuration file with the adapter configuration, allowing you to
call CacheTool withouth `--fcgi` or `--cli` 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

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

Will connect to cli (disregarding fastcgi configuration)

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

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

Add it as a dependency

```sh
$ composer require gordalina/cachetool=~1.0
```

Create instance

```php
use CacheTool\Adapter\FastCGI;
use CacheTool\CacheTool;<commit_msg>simplify composer require in README.md<commit_after>CacheTool - Manage cache in the CLI
===================================

[![Build Status](https://travis-ci.org/gordalina/cachetool.svg?branch=master)](https://travis-ci.org/gordalina/cachetool)
[![HHVM Status](http://hhvm.h4cc.de/badge/gordalina/cachetool.svg)](http://hhvm.h4cc.de/package/gordalina/cachetool)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/gordalina/cachetool/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/gordalina/cachetool/?branch=master)
[![Code Coverage](https://scrutinizer-ci.com/g/gordalina/cachetool/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/gordalina/cachetool/?branch=master)
[![SensioLabsInsight](https://insight.sensiolabs.com/projects/595c9feb-3f4d-473a-a575-81c7e97eb672/mini.png)](https://insight.sensiolabs.com/projects/595c9feb-3f4d-473a-a575-81c7e97eb672)
[![Codacy Badge](https://www.codacy.com/project/badge/2d4176f2526d4251a51b691249c4d3e1)](https://www.codacy.com)

CacheTool allows you to work with `apc` and `opcache` through the cli.
It will connect to a fastcgi server (like php-fpm) and operate it's 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...

Installation
------------

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

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

You can connect to a automatically guessed fastcgi server (if `/var/run/php5-fpm.sock` is a file or `127.0.0.1:9000`)

```sh
$ php cachetool.phar apc:cache:info --fcgi
```

You can connect to a fastcgi server through ip

```sh
$ php cachetool.phar apc:cache:info --fcgi=127.0.0.1:9000
```

Or by socket

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

Or to the cli

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

You have some useful commands that you can you

```sh
apc
  apc:bin:dump             Get a binary dump of files and user variables
  apc:bin:load             Load a binary dump into the APC file and user variables
  apc:cache:clear          Clears APC cache (user, system or all)
  apc:cache:info           Shows APC user & system cache information
  apc:cache:info:file      Shows APC file cache information
  apc:key:delete           Deletes an APC key
  apc:key:exists           Checks if an APC key exists
  apc:key:fetch            Shows the content of an APC key
  apc:key:store            Store an APC key with given value
  apc:sma:info             Show APC shared memory allocation information
opcache
  opcache:configuration    Get configuration information about the cache
  opcache:reset            Resets the contents of the opcode cache
  opcache:status           Show summary information about the opcode cache
  opcache:status:scripts   Show scripts in the opcode cache
```

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

You can have a configuration file with the adapter configuration, allowing you to
call CacheTool withouth `--fcgi` or `--cli` 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

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

Will connect to cli (disregarding fastcgi configuration)

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

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

Add it as a dependency

```sh
$ composer require gordalina/cachetool
```

Create instance

```php
use CacheTool\Adapter\FastCGI;
use CacheTool\CacheTool;
{'fraction_non_alphanumeric': 0.13082437275985664, 'fraction_numerical': 0.02816180235535074, 'mean_word_length': 3.5877862595419847, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 20, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 8, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5023358', 'n_tokens_mistral': 2761, 'n_tokens_neox': 2530, 'n_words': 775}