{"id":13519136,"url":"https://github.com/gordalina/cachetool","last_synced_at":"2025-05-12T13:24:43.611Z","repository":{"id":21039841,"uuid":"24337575","full_name":"gordalina/cachetool","owner":"gordalina","description":"CLI App and library to manage apc \u0026 opcache.","archived":false,"fork":false,"pushed_at":"2025-02-17T10:16:33.000Z","size":14161,"stargazers_count":1738,"open_issues_count":17,"forks_count":157,"subscribers_count":35,"default_branch":"main","last_synced_at":"2025-04-23T06:59:49.859Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://gordalina.github.io/cachetool","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gordalina.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":"gordalina"}},"created_at":"2014-09-22T17:09:20.000Z","updated_at":"2025-04-23T01:30:19.000Z","dependencies_parsed_at":"2024-05-13T21:46:14.862Z","dependency_job_id":"8e9d494f-4be1-4d96-b597-b887586b336f","html_url":"https://github.com/gordalina/cachetool","commit_stats":{"total_commits":481,"total_committers":63,"mean_commits":7.634920634920635,"dds":0.2494802494802495,"last_synced_commit":"3bd0118e03af557ff220d73798e302eddd804c91"},"previous_names":[],"tags_count":98,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gordalina%2Fcachetool","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gordalina%2Fcachetool/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gordalina%2Fcachetool/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gordalina%2Fcachetool/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gordalina","download_url":"https://codeload.github.com/gordalina/cachetool/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253745913,"owners_count":21957465,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T05:01:54.410Z","updated_at":"2025-05-12T13:24:43.587Z","avatar_url":"https://github.com/gordalina.png","language":"PHP","funding_links":["https://github.com/sponsors/gordalina"],"categories":["PHP","目录","Table of Contents","缓存 Caching","缓存( Caching )"],"sub_categories":["缓存和锁定 Caching and Locking","Caching and Locking","Caching","Library"],"readme":"# CacheTool - Manage cache in the CLI\n\n[![Build Status](https://img.shields.io/github/actions/workflow/status/gordalina/cachetool/ci.yml?branch=main\u0026style=flat-square)](https://github.com/gordalina/cachetool/actions)\n[![Coverage Status](https://img.shields.io/coveralls/github/gordalina/cachetool/master?style=flat-square)](https://coveralls.io/github/gordalina/cachetool?branch=master)\n[![Version](https://img.shields.io/github/v/tag/gordalina/cachetool?sort=semver\u0026style=flat-square)](https://github.com/gordalina/cachetool/releases)\n[![Downloads](https://img.shields.io/packagist/dt/gordalina/cachetool?style=flat-square)](https://packagist.org/packages/gordalina/cachetool)\n\nCacheTool allows you to work with APCu, OPcache, and the file status cache\nthrough the CLI. It will connect to a FastCGI server (like PHP-FPM) and operate\non its cache.\n\nWhy is this useful?\n\n- Maybe you want to clear the bytecode cache without reloading php-fpm or using a web endpoint\n- Maybe you want to have a cron which deals with cache invalidation\n- Maybe you want to see some statistics right from the console\n- And many more...\n\nNote 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.\n\n## Installation - Latest version\n\n```sh\ncurl -sLO https://github.com/gordalina/cachetool/releases/latest/download/cachetool.phar\nchmod +x cachetool.phar\n```\n\nYou can alternatively download a compressed phar by using the URLs below.\n\n```sh\n# if your php installation has the zlib extension enabled\nhttps://github.com/gordalina/cachetool/releases/latest/download/cachetool.phar.gz\n\n# if your php installation has the bzip2 extension enabled\nhttps://github.com/gordalina/cachetool/releases/latest/download/cachetool.phar.bz2\n```\n\nCacheTool 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.\n\nSee below for [docker usage instructions](#usage-via-docker).\n\n## Installation - old versions\n\nUse tag name in the binary file name. E.g to download cachetool 3.2.2\nwhich is compatible with PHP `\u003e=5.5.9` use: `cachetool-3.2.2.phar`\n\n```sh\ncurl -sO https://gordalina.github.io/cachetool/downloads/cachetool-3.2.2.phar\nchmod +x cachetool-3.2.2.phar\n```\n\n## Usage\n\nCacheTool requires an adapter to connect to, it can be `cli`, `fcgi`, and `web`.\nThe `fcgi` adapter is the most common, as it connects directly to php-fpm.\n\nYou 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`.\n\n- You can let CacheTool find the unix socket for you, or default to IP.\n\n```sh\nphp cachetool.phar apcu:cache:info --fcgi\n```\n\n- You can connect to a fastcgi server using an IP address\n\n```sh\nphp cachetool.phar apcu:cache:info --fcgi=127.0.0.1:9000\n```\n\n- You can connect to a fastcgi server using a unix socket\n\n```sh\nphp cachetool.phar opcache:status --fcgi=/var/run/php5-fpm.sock\n```\n\n- To connect to a chrooted fastcgi server you need to set `--fcgi-chroot` and `--tmp-dir` parameters\n\n```sh\nphp cachetool.phar opcache:status --fcgi=/var/run/php5-fpm.sock --fcgi-chroot=/path/to/chroot --tmp-dir=/path/to/chroot/tmp\n```\n\n- Using the CLI\n\n```sh\nphp cachetool.phar opcache:status --cli\n```\n\n- Using an HTTP interface\n\n```sh\nphp cachetool.phar opcache:status --web --web-path=/path/to/your/document/root --web-url=http://url-to-your-document.root\n```\n\n- Using SymfonyHttpClient\n\n```sh\nphp cachetool.phar opcache:status --web=SymfonyHttpClient --web-path=/path/to/your/document/root --web-url=http://url-to-your-document.root\n```\n\nYou have some useful commands that you can use\n\n```sh\n apcu\n  apcu:cache:clear            Clears APCu cache\n  apcu:cache:info             Shows APCu user \u0026 system cache information\n  apcu:cache:info:keys        Shows APCu keys cache information\n  apcu:key:delete             Deletes an APCu key\n  apcu:key:exists             Checks if an APCu key exists\n  apcu:key:fetch              Shows the content of an APCu key\n  apcu:key:store              Store an APCu key with given value\n  apcu:regexp:delete          Deletes all APCu key matching a regexp\n  apcu:sma:info               Show APCu shared memory allocation information\n opcache\n  opcache:compile:script      Compile single script from path to the opcode cache\n  opcache:compile:scripts     Compile scripts from path to the opcode cache\n  opcache:configuration       Get configuration information about the cache\n  opcache:invalidate:scripts  Remove scripts from the opcode cache\n  opcache:reset               Resets the contents of the opcode cache\n  opcache:reset:file-cache    Deletes all contents of the file cache directory\n  opcache:status              Show summary information about the opcode cache\n  opcache:status:scripts      Show scripts in the opcode cache\n stat\n  stat:clear                  Clears the file status cache, including the realpath cache\n  stat:realpath_get           Show summary information of realpath cache entries\n  stat:realpath_size          Display size of realpath cache\n```\n\n## Usage via Docker\n\nImages are available in docker hub and github container registries:\n\n- `gordalina/cachetool:latest`\n- `ghcr.io/gordalina/cachetool:latest`\n\nThis is an example run with the `web` adapter:\n\n```sh\nAPPDIR=\"/var/www/example.com\"\nDOCROOT=\"/var/www/example.com/current/web\"\nURL=\"http://example.com\"\n\ndocker run --rm -v $APPDIR:$APPDIR -w $DOCROOT gordalina/cachetool cachetool --web --web-url=$URL [options] [arguments]\n```\n\nIf 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:\n\n```sh\nDOMAIN=\"example.com\"\nPORT=\"8008\"\nAPPDIR=\"/var/www/example.com\"\nDOCROOT=\"/var/www/example.com/current/web\"\nURL=\"http://$DOMAIN:$PORT\"\n\ndocker run --rm --add-host $DOMAIN:172.17.0.1 -v $APPDIR:$APPDIR -w $DOCROOT sbitio/cachetool --web --web-url=$URL [options] [arguments]\n```\n\nThank you to @jonhattan and @NITEMAN for the [work with docker](https://github.com/sbitio/docker-cachetool).\n\n\n## Configuration File\n\nYou can have a configuration file with the adapter configuration, allowing you to\ncall CacheTool without `--fcgi`, `--cli`, or `--web` option.\n\nYou can pass a `--config \u003cfile\u003e` option to the application or it will choose to load\na file automaically.\n\nThe file must be named `.cachetool.yml` or `.cachetool.yaml`. CacheTool will look for\nthis file on the current directory and in any parent directory until it finds one.\nIf the paths above fail it will try to load `/etc/cachetool.yml` or `/etc/cachetool.yaml` configuration file.\n\nAn example of what this file might look like is:\n\nWill connect to fastcgi at 127.0.0.1:9000\n\n```yml\nadapter: fastcgi\nfastcgi: 127.0.0.1:9000\n```\n\nWill connect to cli (disregarding fastcgi configuration)\n\n```yml\nadapter: cli\nfastcgi: /var/run/php5-fpm.sock\n```\n\nCacheTool writes files to the system temporary directory (given by `sys_get_temp_dir()`)\nbut if you want to change this, for example, if your fastcgi service is run with PrivateTemp\nyou can set it on the config file:\n\n```yml\nadapter: fastcgi\nfastcgi: /var/run/php5-fpm.sock\ntemp_dir: /dev/shm/cachetool\n```\n\nExample for the web adapter:\n\n```yml\nadapter: web\nwebClient: SymfonyHttpClient # defaults to FileGetContents\nwebUrl: http://example.com\nwebPath: /var/www/example.com/current/web\nwebBasicAuth: user:password\n```\n\nYou can define the supported extensions in the config file. By default, `apcu`,\nand `opcache` are enabled. To disable `apcu`, add this to your config file:\n\n```yml\nextensions: [opcache]\n```\n\n## Usage (as a library)\n\nAdd it as a dependency\n\n```sh\ncomposer require gordalina/cachetool\n```\n\nIf you want to use it in a Symfony 2.x project, require the `1.x` version\n\n```sh\ncomposer require gordalina/cachetool:~1.0\n```\n\nCreate instance\n\n```php\nuse CacheTool\\Adapter\\FastCGI;\nuse CacheTool\\CacheTool;\n\n$adapter = new FastCGI('127.0.0.1:9000');\n$cache = CacheTool::factory($adapter, '/tmp');\n```\n\nYou can use `apcu` and `opcache` functions\n\n```php\n$cache-\u003eapcu_clear_cache();\n$cache-\u003eopcache_reset();\n```\n\n## Proxies\n\nCacheTool depends on `Proxies` to provide functionality, by default when creating a CacheTool instance from the factory\nall 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:\n\n```php\nuse CacheTool\\Adapter\\FastCGI;\nuse CacheTool\\CacheTool;\nuse CacheTool\\Proxy;\n\n$adapter = new FastCGI('/var/run/php5-fpm.sock');\n$cache = new CacheTool();\n$cache-\u003esetAdapter($adapter);\n$cache-\u003eaddProxy(new Proxy\\ApcuProxy());\n$cache-\u003eaddProxy(new Proxy\\PhpProxy());\n```\n\n## Updating CacheTool\n\nRunning `php cachetool.phar self-update` will update a phar install with the latest version.\n\n## Building cachetool.phar\n\nCachetool 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.\n\n## Testing\n\nAfter running `composer install`, run `./vendor/bin/phpunit`\n\n### Troubleshooting test failures\n\n#### sslip.io\n\nTests 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.\n\n## Version Compatibility\n\n| CacheTool | PHP\n| - | -\n| `9.x` | `\u003e=8.1`\n| `8.x` | `\u003e=8.0`\n| `7.x` | `\u003e=7.3`\n| `6.x` | `\u003e=7.3`\n| `5.x` | `\u003e=7.2`\n| `4.x` | `\u003e=7.1`\n| `3.x` | `\u003e=5.5.9`\n| `2.x` | `\u003e=5.5.9`\n| `1.x` | `\u003e=5.3.3`\n\n## License\n\nCacheTool is licensed under the MIT License - see the [LICENSE](LICENSE) for details\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgordalina%2Fcachetool","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgordalina%2Fcachetool","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgordalina%2Fcachetool/lists"}