CLI App and library to manage apc & opcache.

Related tags

Caching cachetool
Overview

CacheTool - Manage cache in the CLI

Build Status Scrutinizer Code Quality Code Coverage

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 with more details on how the file status cache operates.

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

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

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

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

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 https://hub.docker.com/r/sbitio/cachetool

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: https://github.com/sbitio/docker-cachetool

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

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)

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

CacheTool depends on Proxies to provide functionality, by default when creating a CacheTool instance from the factory all proxies are enabled ApcuProxy, OpcacheProxy and PhpProxy, 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

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

Testing

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

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

To have cachetool working with SELinux read this comment by @driskell.

License

CacheTool is licensed under the MIT License - see the LICENSE for details

Comments
  • file_get_contents() call failed with url

    file_get_contents() call failed with url

    I've installed Version 6.1.1 and sometimes got the following error:

    SYMFONY_ENV=prod php bin/cachetool opcache:reset --web --web-path=/var/www/html/example.org/public --web-url=https://example.org
    

    As you can see its a symfony webapplication. An Apache-VHost is configured with the DocumentRoot equal to /var/www/html/example.org/public.

    Do you have any hint or suggestions? Its maybe the same issue as #145 .

    Now trying to set the symlink target (which is the DocRoot) for --web-path

    opened by FireLizard 19
  • cachetool via fcgi doesn't work if php-fpm starts with systemd unit  set to PrivateTmp=true

    cachetool via fcgi doesn't work if php-fpm starts with systemd unit set to PrivateTmp=true

    If the php-fpm systemd unit file has PrivateTmp=true and you run cachetool with this:

    cachetool  opcache:status -vvv --fcgi /var/run/php-fpm/php-fpm.sock
    

    then you see this in the logs (snipped to the relevant part):

    [2015-01-06 20:55:05] cachetool.DEBUG: Executing code: return extension_loaded('Zend OPcache'); [] []
    [2015-01-06 20:55:05] cachetool.INFO: FastCGI: Dumped code to file: /tmp/cachetool-54ac91f90c03f.php [] []
    object(CacheTool\Code)#82 (1) {
      ["code":protected]=>
      array(1) {
        [0]=>
        string(40) "return extension_loaded('Zend OPcache');"
      }
    }
    [2015-01-06 20:55:05] cachetool.DEBUG: FastCGI: Response: {"statusCode":404,"headers":{"status":"404 Not Found","content-type":"text\/html; charset=UTF-8"},"body":"File not found.","stderr":"Primary script unknown\n"} [] []
    
    
    
      [RuntimeException]      
      Primary script unknown  
    
    opened by jrobeson 17
  • Opcache errors after deployment with symlink switch

    Opcache errors after deployment with symlink switch

    Even though we are invoking the cachetool during deployment to reset the PHP opcode cache, we encounter internal server errors after the symlink switch to the new release. The error disappears after a short while.

    To verify that everything is basically working correct we have also put opcache:status before and after opcache:reset:

    $ .../bin/cachetool opcache:status
    +----------------------+---------------------------------+
    | Name                 | Value                           |
    +----------------------+---------------------------------+
    | Enabled              | Yes                             |
    | Cache full           | No                              |
    | Restart pending      | No                              |
    | Restart in progress  | No                              |
    | Memory used          | 53.81 MiB                       |
    | Memory free          | 74.19 MiB                       |
    | Memory wasted (%)    | 0 b (0%)                        |
    | Strings buffer size  | 16 MiB                          |
    | Strings memory used  | 6.73 MiB                        |
    | Strings memory free  | 9.27 MiB                        |
    | Number of strings    | 335325                          |
    +----------------------+---------------------------------+
    | Cached scripts       | 1054                            |
    | Cached keys          | 1372                            |
    | Max cached keys      | 16229                           |
    | Start time           | Fri, 12 Feb 2016 14:04:08 +0000 |
    | Last restart time    | Tue, 16 Feb 2016 10:32:12 +0000 |
    | Oom restarts         | 0                               |
    | Hash restarts        | 0                               |
    | Manual restarts      | 7                               |
    | Hits                 | 8193                            |
    | Misses               | 1073                            |
    | Blacklist misses (%) | 0 (0%)                          |
    | Opcache hit rate     | 88.420030218001                 |
    +----------------------+---------------------------------+
    
    $ .../bin/cachetool opcache:reset
    
    $ .../bin/cachetool opcache:status
    +----------------------+---------------------------------+
    | Name                 | Value                           |
    +----------------------+---------------------------------+
    | Enabled              | Yes                             |
    | Cache full           | No                              |
    | Restart pending      | No                              |
    | Restart in progress  | No                              |
    | Memory used          | 20.87 MiB                       |
    | Memory free          | 107.13 MiB                      |
    | Memory wasted (%)    | 0 b (0%)                        |
    | Strings buffer size  | 16 MiB                          |
    | Strings memory used  |  452.05 KiB                     |
    | Strings memory free  | 15.56 MiB                       |
    | Number of strings    | 335325                          |
    +----------------------+---------------------------------+
    | Cached scripts       | 0                               |
    | Cached keys          | 0                               |
    | Max cached keys      | 16229                           |
    | Start time           | Fri, 12 Feb 2016 14:04:08 +0000 |
    | Last restart time    | Tue, 16 Feb 2016 12:08:43 +0000 |
    | Oom restarts         | 0                               |
    | Hash restarts        | 0                               |
    | Manual restarts      | 8                               |
    | Hits                 | 0                               |
    | Misses               | 2                               |
    | Blacklist misses (%) | 0 (0%)                          |
    | Opcache hit rate     | 0                               |
    +----------------------+---------------------------------+
    

    While I'm not sure about the memory and string usage, scripts and keys are indeed removed as expected.

    This is an environment with an Apache 2.4.10 and PHP 5.6.17 with PHP-FPM. The relevant part of the php.ini:

    opcache.enable=1
    opcache.memory_consumption=128
    opcache.interned_strings_buffer=16
    opcache.max_accelerated_files=8192
    opcache.validate_timestamps=0
    opcache.revalidate_freq=0
    

    Any idea what could be wrong?

    opened by mbrodala 15
  • Not in white list. Check listen.allowed_clients

    Not in white list. Check listen.allowed_clients

    We use cachetool in our (automated) deploys. Once in a while this fails with a RuntimeException

    FastCGI error: Not in white list. Check listen.allowed_clients.
    

    It would be nice if cachetool could deal with this more gracefully (e.g. try again a few times and exit) instead of throwing an exception.

    This happens on Ubuntu 16.04 + PHP 7.0.21

    question 
    opened by syphernl 14
  • Fatal error on PHP8

    Fatal error on PHP8

    On PHP 8 command ./cachetool.phar opcache:reset results to the fatal error:

    PHP Fatal error:  Declaration of Symfony\Component\DependencyInjection\ServiceLocator::has(string $id) must be compatible with Psr\Container\ContainerInterface::has($id) in phar:///home/longman/project/cachetool.phar/vendor/symfony/dependency-injection/ServiceLocator.php on line 46
    PHP Stack trace:
    PHP   1. {main}() /home/longman/project/cachetool.phar:0
    PHP   2. require() /home/longman/project/cachetool.phar:14
    PHP   3. CacheTool\Console\Application->run($input = *uninitialized*, $output = *uninitialized*) phar:///home/longman/project/cachetool.phar/bin/cachetool:26
    PHP   4. CacheTool\Console\Application->doRun($input = class Symfony\Component\Console\Input\ArgvInput { private $tokens = [0 => 'opcache:reset']; private $parsed = []; protected $definition = class Symfony\Component\Console\Input\InputDefinition { private $arguments = [...]; private $requiredCount = 1; private $hasAnArrayArgument = FALSE; private $hasOptional = FALSE; private $options = [...]; private $shortcuts = [...] }; protected $stream = NULL; protected $options = []; protected $arguments = ['command' => 'opcache:reset']; protected $interactive = TRUE }, $output = class Symfony\Component\Console\Output\ConsoleOutput { private $stderr = class Symfony\Component\Console\Output\StreamOutput { private $stream = resource(134) of type (stream); private ${Symfony\Component\Console\Output\Output}verbosity = 32; private ${Symfony\Component\Console\Output\Output}formatter = class Symfony\Component\Console\Formatter\OutputFormatter { ... } }; private $consoleSectionOutputs = []; private ${Symfony\Component\Console\Output\StreamOutput}stream = resource(119) of type (stream); private ${Symfony\Component\Console\Output\Output}verbosity = 32; private ${Symfony\Component\Console\Output\Output}formatter = class Symfony\Component\Console\Formatter\OutputFormatter { private $decorated = TRUE; private $styles = [...]; private $styleStack = class Symfony\Component\Console\Formatter\OutputFormatterStyleStack { ... } } }) phar:///home/longman/project/cachetool.phar/vendor/symfony/console/Application.php:166
    PHP   5. CacheTool\Console\Application->doRun($input = class Symfony\Component\Console\Input\ArgvInput { private $tokens = [0 => 'opcache:reset']; private $parsed = []; protected $definition = class Symfony\Component\Console\Input\InputDefinition { private $arguments = [...]; private $requiredCount = 1; private $hasAnArrayArgument = FALSE; private $hasOptional = FALSE; private $options = [...]; private $shortcuts = [...] }; protected $stream = NULL; protected $options = []; protected $arguments = ['command' => 'opcache:reset']; protected $interactive = TRUE }, $output = class Symfony\Component\Console\Output\ConsoleOutput { private $stderr = class Symfony\Component\Console\Output\StreamOutput { private $stream = resource(134) of type (stream); private ${Symfony\Component\Console\Output\Output}verbosity = 32; private ${Symfony\Component\Console\Output\Output}formatter = class Symfony\Component\Console\Formatter\OutputFormatter { ... } }; private $consoleSectionOutputs = []; private ${Symfony\Component\Console\Output\StreamOutput}stream = resource(119) of type (stream); private ${Symfony\Component\Console\Output\Output}verbosity = 32; private ${Symfony\Component\Console\Output\Output}formatter = class Symfony\Component\Console\Formatter\OutputFormatter { private $decorated = TRUE; private $styles = [...]; private $styleStack = class Symfony\Component\Console\Formatter\OutputFormatterStyleStack { ... } } }) phar:///home/longman/project/cachetool.phar/src/Console/Application.php:129
    PHP   6. CacheTool\Console\Application->doRunCommand($command = class CacheTool\Command\OpcacheResetCommand { protected $container = NULL; private ${Symfony\Component\Console\Command\Command}application = class CacheTool\Console\Application { protected $config = class CacheTool\Console\Config { ... }; protected $logger = class Monolog\Logger { ... }; private ${Symfony\Component\Console\Application}commands = [...]; private ${Symfony\Component\Console\Application}wantHelps = FALSE; private ${Symfony\Component\Console\Application}runningCommand = ...; private ${Symfony\Component\Console\Application}name = 'CacheTool'; private ${Symfony\Component\Console\Application}version = '6.3.1'; private ${Symfony\Component\Console\Application}commandLoader = NULL; private ${Symfony\Component\Console\Application}catchExceptions = TRUE; private ${Symfony\Component\Console\Application}autoExit = TRUE; private ${Symfony\Component\Console\Application}definition = class Symfony\Component\Console\Input\InputDefinition { ... }; private ${Symfony\Component\Console\Application}helperSet = class Symfony\Component\Console\Helper\HelperSet { ... }; private ${Symfony\Component\Console\Application}dispatcher = NULL; private ${Symfony\Component\Console\Application}terminal = class Symfony\Component\Console\Terminal { ... }; private ${Symfony\Component\Console\Application}defaultCommand = 'list'; private ${Symfony\Component\Console\Application}singleCommand = FALSE; private ${Symfony\Component\Console\Application}initialized = TRUE; private ${Symfony\Component\Console\Application}signalRegistry = class Symfony\Component\Console\SignalRegistry\SignalRegistry { ... }; private ${Symfony\Component\Console\Application}signalsToDispatchEvent = [...] }; private ${Symfony\Component\Console\Command\Command}name = 'opcache:reset'; private ${Symfony\Component\Console\Command\Command}processTitle = NULL; private ${Symfony\Component\Console\Command\Command}aliases = []; private ${Symfony\Component\Console\Command\Command}definition = class Symfony\Component\Console\Input\InputDefinition { private $arguments = [...]; private $requiredCount = 0; private $hasAnArrayArgument = FALSE; private $hasOptional = FALSE; private $options = [...]; private $shortcuts = [...] }; private ${Symfony\Component\Console\Command\Command}hidden = FALSE; private ${Symfony\Component\Console\Command\Command}help = ''; private ${Symfony\Component\Console\Command\Command}description = 'Resets the contents of the opcode cache'; private ${Symfony\Component\Console\Command\Command}fullDefinition = NULL; private ${Symfony\Component\Console\Command\Command}ignoreValidationErrors = FALSE; private ${Symfony\Component\Console\Command\Command}code = NULL; private ${Symfony\Component\Console\Command\Command}synopsis = []; private ${Symfony\Component\Console\Command\Command}usages = []; private ${Symfony\Component\Console\Command\Command}helperSet = class Symfony\Component\Console\Helper\HelperSet { private $helpers = [...]; private $command = NULL } }, $input = class Symfony\Component\Console\Input\ArgvInput { private $tokens = [0 => 'opcache:reset']; private $parsed = []; protected $definition = class Symfony\Component\Console\Input\InputDefinition { private $arguments = [...]; private $requiredCount = 1; private $hasAnArrayArgument = FALSE; private $hasOptional = FALSE; private $options = [...]; private $shortcuts = [...] }; protected $stream = NULL; protected $options = []; protected $arguments = ['command' => 'opcache:reset']; protected $interactive = TRUE }, $output = class Symfony\Component\Console\Output\ConsoleOutput { private $stderr = class Symfony\Component\Console\Output\StreamOutput { private $stream = resource(134) of type (stream); private ${Symfony\Component\Console\Output\Output}verbosity = 32; private ${Symfony\Component\Console\Output\Output}formatter = class Symfony\Component\Console\Formatter\OutputFormatter { ... } }; private $consoleSectionOutputs = []; private ${Symfony\Component\Console\Output\StreamOutput}stream = resource(119) of type (stream); private ${Symfony\Component\Console\Output\Output}verbosity = 32; private ${Symfony\Component\Console\Output\Output}formatter = class Symfony\Component\Console\Formatter\OutputFormatter { private $decorated = TRUE; private $styles = [...]; private $styleStack = class Symfony\Component\Console\Formatter\OutputFormatterStyleStack { ... } } }) phar:///home/longman/project/cachetool.phar/vendor/symfony/console/Application.php:290
    PHP   7. CacheTool\Console\Application->buildContainer($input = class Symfony\Component\Console\Input\ArgvInput { private $tokens = [0 => 'opcache:reset']; private $parsed = []; protected $definition = class Symfony\Component\Console\Input\InputDefinition { private $arguments = [...]; private $requiredCount = 1; private $hasAnArrayArgument = FALSE; private $hasOptional = FALSE; private $options = [...]; private $shortcuts = [...] }; protected $stream = NULL; protected $options = []; protected $arguments = ['command' => 'opcache:reset']; protected $interactive = TRUE }) phar:///home/longman/project/cachetool.phar/src/Console/Application.php:142
    PHP   8. Composer\Autoload\ClassLoader->loadClass($class = 'Symfony\\Component\\DependencyInjection\\Container') phar:///home/longman/project/cachetool.phar/src/Console/Application.php:166
    PHP   9. Composer\Autoload\includeFile($file = 'phar:///home/longman/project/cachetool.phar/vendor/composer/../symfony/dependency-injection/Container.php') phar:///home/longman/project/cachetool.phar/.box/vendor/composer/ClassLoader.php:322
    PHP  10. include() phar:///home/longman/project/cachetool.phar/.box/vendor/composer/ClassLoader.php:444
    PHP  11. class_exists($class = 'Symfony\\Component\\DependencyInjection\\Argument\\ServiceLocator') phar:///home/longman/project/cachetool.phar/vendor/symfony/dependency-injection/Container.php:29
    PHP  12. Composer\Autoload\ClassLoader->loadClass($class = 'Symfony\\Component\\DependencyInjection\\Argument\\ServiceLocator') phar:///home/longman/project/cachetool.phar/vendor/symfony/dependency-injection/Container.php:29
    PHP  13. Composer\Autoload\includeFile($file = 'phar:///home/longman/project/cachetool.phar/vendor/composer/../symfony/dependency-injection/Argument/ServiceLocator.php') phar:///home/longman/project/cachetool.phar/.box/vendor/composer/ClassLoader.php:322
    PHP  14. include() phar:///home/longman/project/cachetool.phar/.box/vendor/composer/ClassLoader.php:444
    PHP  15. Composer\Autoload\ClassLoader->loadClass($class = 'Symfony\\Component\\DependencyInjection\\ServiceLocator') phar:///home/longman/project/cachetool.phar/vendor/symfony/dependency-injection/Argument/ServiceLocator.php:21
    PHP  16. Composer\Autoload\includeFile($file = 'phar:///home/longman/project/cachetool.phar/vendor/composer/../symfony/dependency-injection/ServiceLocator.php') phar:///home/longman/project/cachetool.phar/.box/vendor/composer/ClassLoader.php:322
    PHP  17. include() phar:///home/longman/project/cachetool.phar/.box/vendor/composer/ClassLoader.php:444
    

    Version of cachetool is 6.3.1

    opened by akalongman 11
  • Machine output

    Machine output

    I'd like to monitor Memory free every two minutes.

    It would be nice to have cachetool opcache:status --format=json

    In WP-CLI there are:

    – table – csv – json – yaml

    opened by szepeviktor 11
  • if PHP_BINARY constant exists use it as php-binary in cli-adapter

    if PHP_BINARY constant exists use it as php-binary in cli-adapter

    On some systems it is not possible use the php-binary from path. Therefore it would be useful, to utilize the same php binary used to invoke the cachetool in the cli-adapters process. This PR makes it possible. It does not change the default behaviour, so if one uses the cachetool like …

    cachetool.phar --cli opcache:reset (with cachetool.phar being executable) php cachetool.phar --cli opcache:reset (with explicit php-binary)

    … the same php-binary will be used, as without this PR.

    In my case I run cachetool like …

    /opt/local/bin/php72 cachetool.phar --cli opcache:reset

    … and without this PR, it fails because there is a php-binary in PATH (/usr/bin/php), which does not have the Opcache enabled. And actually it would be wrong to clear the opcache in this binaries context.

    I appreciate any Feedback on this … Cheers, Stephan

    opened by brandung-sjorek 9
  • FastCGI.php line 114: Error: File not found. (when using configuration file)

    FastCGI.php line 114: Error: File not found. (when using configuration file)

    I'm a bit baffled by this.

    CacheTool: 8.4.0 PHP: 8.1.5

    Running the command with arguments cachetool opcache:status --fcgi=127.0.0.1:9000 works as expected but as soon as I use a .cachetool.yml I always get an error:

    In FastCGI.php line 114:
    
      Error: File not found.
    

    This is my .cachetool.yml:

    adapter: fastcgi
    fastcgi: 127.0.0.1:9000
    

    Without any .cachetool.yml:

    $ cachetool opcache:status --fcgi=127.0.0.1:9000
    +----------------------+---------------------------------+
    | Name                 | Value                           |
    +----------------------+---------------------------------+
    | Enabled              | Yes                             |
    | Cache full           | No                              |
    | Restart pending      | No                              |
    | Restart in progress  | No                              |
    | Memory used          | 106.33 MiB                      |
    | Memory free          | 21.67 MiB                       |
    | Memory wasted (%)    | 0 b (0%)                        |
    | Strings buffer size  | 6 MiB                           |
    | Strings memory used  | 6 MiB                           |
    | Strings memory free  | 0 b                             |
    | Number of strings    | 53224                           |
    +----------------------+---------------------------------+
    | Cached scripts       | 3424                            |
    | Cached keys          | 6742                            |
    | Max cached keys      | 16229                           |
    | Start time           | Wed, 11 May 2022 11:02:52 +0100 |
    | Last restart time    | Never                           |
    | Oom restarts         | 0                               |
    | Hash restarts        | 0                               |
    | Manual restarts      | 0                               |
    | Hits                 | 67059                           |
    | Misses               | 3434                            |
    | Blacklist misses (%) | 0 (0%)                          |
    | Opcache hit rate     | 95.128594328515                 |
    +----------------------+---------------------------------+
    

    With the .cachetool.yml as described above:

    $ cachetool opcache:status
    
    In FastCGI.php line 114:
    
      Error: File not found.
    
    
    opcache:status
    
    
    opened by bluec 8
  • cachetool doesn't work out of the box with SELinux

    cachetool doesn't work out of the box with SELinux

    You get a 404 on the fastgi response because it doesn't have the permission to read the cachetool generated file.

    I'm not sure if this is really solvable without changing selinux configuration, but i do wonder if the stdin option of the fastcgi client would fix it.

    Can you think of a quick hack to try that out?

    opened by jrobeson 8
  • PHP 8.1 - after instalation via dockerifle - deprecated messages

    PHP 8.1 - after instalation via dockerifle - deprecated messages

    after instalation cachetool via dockerfile (php:8.1-fpm)

    && curl --fail -sOL https://gordalina.github.io/cachetool/downloads/cachetool-8.0.2.phar && chmod +x cachetool-8.0.2.phar && mv cachetool-8.0.2.phar /usr/local/bin/cachetool \

    it shows deprecated messages:

    Deprecated: Return type of HumbugBox3100\KevinGH\RequirementChecker\RequirementCollection::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in phar:///usr/local/bin/cachetool/.box/src/RequirementCollection.php on line 12

    Deprecated: Return type of HumbugBox3100\KevinGH\RequirementChecker\RequirementCollection::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in phar:///usr/local/bin/cachetool/.box/src/RequirementCollection.php on line 16

    opened by tkorcina 7
  • Require fails if psr/container 1.1.1 is required elsewhere

    Require fails if psr/container 1.1.1 is required elsewhere

    Hi

    I use the symfony/dependency-injection on my project using Symfony 5.3, which is locked in composer.lock to "version": "v5.3.0" This packages requires psr/container ^1.1.1

    Due to recent changes in the composer.json of gordalina/cachetool, I cannot require it in the project since the two packages require different versions of psr/container

      Problem 1
        - Root composer.json requires gordalina/cachetool ^6.5 -> satisfiable by gordalina/cachetool[6.5.0].
        - gordalina/cachetool 6.5.0 requires psr/container 1.0.0 -> found psr/container[1.0.0] but the package is fixed to 1.1.1 (lock file version) by a partial update and that version does not match. Make sure you list it as an argument for the update command.
    

    Is there any fix that you can push to make it work ? Thanks!

    opened by edouardgat 7
  • Refactor parse configuration

    Refactor parse configuration

    • Using parsed valued via getOption where possible
    • Merge flags with preset value consistently
    • Use VALUE_NONE for option --web-allow-insecure which does not allow for a value to be set.
    opened by sideshowcoder 0
  • Skip sslip.io tests if DNS is not configured

    Skip sslip.io tests if DNS is not configured

    In case sslip.io DNS is not configured correctly on the running host the tests will fail, skip instead in this case as the failure would not be related to a failing code but dependend on the running hosts DNS configuration.

    opened by sideshowcoder 0
  • Try fixing race conditions between --web file creation and HTTP access

    Try fixing race conditions between --web file creation and HTTP access

    On some hosters' storage systems it happens that although the cache busting PHP file is created fine, the subsequent access via HTTP fails (404).

    This PR is to explore possiblities how to make cachetool more resilient against that.

    The first step is just to see if sleep() between creation and HTTP-accessing would help. Of course that would have to be configurable if that approach is chosen.

    Other possiblities might be to retry $this->http->fetch() some times (maybe each second or so, max. 5 tries?).

    If others want to try that in their pipelines: In a composer project, the easiest is to install cweagans/composer-patches and configure by:

    "extra": {
      "patches": {
        "gordalina/cachetool": {
          "Try fixing race conditions between --web file creation and HTTP access": "https://patch-diff.githubusercontent.com/raw/gordalina/cachetool/pull/210.patch"
        }
      }
    }
    

    The patch applies to v7 and v8.

    I am happy to get feedback.

    Relates: #209

    opened by jonaseberle 4
  • 404 when using --web

    404 when using --web

    With the --web adapter it happens that we get 404 because it might be just too fast for some hosters to create the file and access it through the web near-instantaneously. I guess this is related to their storage and file system caches, maybe also PHP stat cache?

    Current workaround: It will usually succeed after some tries...

    ./cachetool stat:clear --web=SymfonyHttpClient --web-url=https://.../ --web-path=./public/ --web-host

    It is currently holding us a bit back on systems where we can't use --fcgi.

    Splitting this off from #199 which is about retrying the whole procedure which can probably mostly be avoided in this case.

    help wanted 
    opened by jonaseberle 3
  • Wouldn't it be better to have in composer.json just PHP version dependancy?

    Wouldn't it be better to have in composer.json just PHP version dependancy?

    Hello,

    Wouldn't it be better to have in composer.json just PHP version dependancy? And deal with everything else via phar. Similar to https://github.com/phpstan/phpstan.

    I would like to install it via composer but sometimes I have dependencies in my project which conflicts with those in cachetool. Then I need to install it via

    curl -sLO https://github.com/gordalina/cachetool/releases/latest/download/cachetool.phar
    chmod +x cachetool.phar
    

    but I'm losing PHP version check.

    Thank you.

    enhancement help wanted 
    opened by thorewi 3
Releases(9.0.0)
A clean and responsive interface for Zend OPcache information,

A clean and responsive interface for Zend OPcache information, showing statistics, settings and cached files, and providing a real-time update for the information.

Andrew Collington 1.1k Dec 27, 2022
LaraCache is an ORM based package for Laravel to create, update and manage cache items based on model queries

LaraCache Using this package, you can cache your heavy and most used queries. All you have to do is to define the CacheEntity objects in the model and

Mostafa Zeinivand 202 Dec 19, 2022
A simple cache library. Implements different adapters that you can use and change easily by a manager or similar.

Desarolla2 Cache A simple cache library, implementing the PSR-16 standard using immutable objects. Caching is typically used throughout an applicatito

Daniel González 129 Nov 20, 2022
A library providing platform-specific user directory paths, such as config and cache

Phirs A library providing platform-specific user directory paths, such as config and cache. Inspired by dirs-rs.

Mohammad Amin Chitgarha 7 Mar 1, 2022
A simple cache library. Implements different adapters that you can use and change easily by a manager or similar.

Desarolla2 Cache A simple cache library, implementing the PSR-16 standard using immutable objects. Caching is typically used throughout an applicatito

Daniel González 129 Nov 20, 2022
[READ-ONLY] Easy to use Caching library with support for multiple caching backends. This repo is a split of the main code that can be found in https://github.com/cakephp/cakephp

CakePHP Caching Library The Cache library provides a Cache service locator for interfacing with multiple caching backends using a simple to use interf

CakePHP 49 Sep 28, 2022
Yii Caching Library - Redis Handler

Yii Caching Library - Redis Handler This package provides the Redis handler and implements PSR-16 cache. Requirements PHP 7.4 or higher. Installation

Yii Software 4 Oct 9, 2022
Stash - A PHP Caching Library

Stash - A PHP Caching Library Stash makes it easy to speed up your code by caching the results of expensive functions or code. Certain actions, like d

Tedious Developments 943 Dec 15, 2022
Symfony Bundle for the Stash Caching Library

TedivmStashBundle The TedivmStashBundle integrates the Stash caching library into Symfony, providing a powerful abstraction for a range of caching eng

Tedious Developments 86 Aug 9, 2022
DataLoaderPhp is a generic utility to be used as part of your application's data fetching layer to provide a simplified and consistent API over various remote data sources such as databases or web services via batching and caching.

DataLoaderPHP is a generic utility to be used as part of your application's data fetching layer to provide a simplified and consistent API over various remote data sources such as databases or web services via batching and caching.

Webedia - Overblog 185 Nov 3, 2022
A thin PSR-6 cache wrapper with a generic interface to various caching backends emphasising cache tagging and indexing.

Apix Cache, cache-tagging for PHP Apix Cache is a generic and thin cache wrapper with a PSR-6 interface to various caching backends and emphasising ca

Apix 111 Nov 26, 2022
A flexible and feature-complete Redis client for PHP.

Predis A flexible and feature-complete Redis client for PHP 7.2 and newer. ATTENTION: you are on the README file of an unstable branch of Predis speci

Predis 7.3k Jan 3, 2023
Simple and swift MongoDB abstraction.

Monga A simple and swift MongoDB abstraction layer for PHP 5.4+ What's this all about? An easy API to get connections, databases and collections. A fi

The League of Extraordinary Packages 330 Nov 28, 2022
Boost the speed of Kirby by having content files of pages cached, with automatic unique ID, fast lookup and Tiny-URL.

?? Kirby3 Boost ⏱️ up to 3x faster content loading ?? fastest page lookup and resolution of relations Boost the speed of Kirby by having content files

Bruno Meilick 41 Jan 8, 2023
Caching implementation with a variety of storage options, as well as codified caching strategies for callbacks, classes, and output

laminas-cache Laminas\Cache provides a general cache system for PHP. The Laminas\Cache component is able to cache different patterns (class, object, o

Laminas Project 69 Jan 7, 2023
A fast, light-weight proxy for memcached and redis

twemproxy (nutcracker) twemproxy (pronounced "two-em-proxy"), aka nutcracker is a fast and lightweight proxy for memcached and redis protocol. It was

Twitter 11.7k Jan 2, 2023
The cache component provides a Promise-based CacheInterface and an in-memory ArrayCache implementation of that

Cache Async, Promise-based cache interface for ReactPHP. The cache component provides a Promise-based CacheInterface and an in-memory ArrayCache imple

ReactPHP 330 Dec 6, 2022
Graphic stand-alone administration for memcached to monitor and debug purpose

PHPMemcachedAdmin Graphic stand-alone administration for memcached to monitor and debug purpose This program allows to see in real-time (top-like) or

Cyrille Mahieux 249 Nov 15, 2022
PHP cache library, with adapters for e.g. Memcached, Redis, Couchbase, APC(u), SQL and additional capabilities (e.g. transactions, stampede protection) built on top.

Donate/Support: Documentation: https://www.scrapbook.cash - API reference: https://docs.scrapbook.cash Table of contents Installation & usage Adapters

Matthias Mullie 295 Nov 28, 2022
A clean and responsive interface for Zend OPcache information,

A clean and responsive interface for Zend OPcache information, showing statistics, settings and cached files, and providing a real-time update for the information.

Andrew Collington 1.1k Dec 27, 2022