{"id":13684369,"url":"https://github.com/cnizzardini/cakephp-preloader","last_synced_at":"2026-02-15T17:44:10.488Z","repository":{"id":38289715,"uuid":"367684466","full_name":"cnizzardini/cakephp-preloader","owner":"cnizzardini","description":"An OPCache Preloader for CakePHP 4 and 5 applications","archived":false,"fork":false,"pushed_at":"2025-04-19T13:41:59.000Z","size":76,"stargazers_count":12,"open_issues_count":0,"forks_count":4,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-05-28T07:52:19.840Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/cnizzardini.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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}},"created_at":"2021-05-15T16:51:18.000Z","updated_at":"2025-05-27T01:38:54.000Z","dependencies_parsed_at":"2023-10-15T00:23:43.449Z","dependency_job_id":"9af10426-608c-4340-942c-1412d801bae8","html_url":"https://github.com/cnizzardini/cakephp-preloader","commit_stats":{"total_commits":38,"total_committers":1,"mean_commits":38.0,"dds":0.0,"last_synced_commit":"b7ba84a17af8424b0e46ae60eaea1f68c9e64abd"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/cnizzardini/cakephp-preloader","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cnizzardini%2Fcakephp-preloader","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cnizzardini%2Fcakephp-preloader/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cnizzardini%2Fcakephp-preloader/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cnizzardini%2Fcakephp-preloader/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cnizzardini","download_url":"https://codeload.github.com/cnizzardini/cakephp-preloader/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cnizzardini%2Fcakephp-preloader/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262546982,"owners_count":23327076,"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-02T14:00:32.813Z","updated_at":"2026-02-15T17:44:10.443Z","avatar_url":"https://github.com/cnizzardini.png","language":"PHP","readme":"# CakePHP Preloader\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/cnizzardini/cakephp-preloader.svg?style=flat-square)](https://packagist.org/packages/cnizzardini/cakephp-preloader)\n[![Build](https://github.com/cnizzardini/cakephp-preloader/actions/workflows/merge.yml/badge.svg)](https://github.com/cnizzardini/cakephp-preloader/actions/workflows/merge.yml)\n[![Coverage Status](https://coveralls.io/repos/github/cnizzardini/cakephp-preloader/badge.svg?branch=main)](https://coveralls.io/github/cnizzardini/cakephp-preloader?branch=main)\n[![License: MIT](https://img.shields.io/badge/license-mit-blue)](LICENSE.md)\n[![CakePHP](https://img.shields.io/badge/cakephp-^5.0-red?logo=cakephp)](https://book.cakephp.org/4/en/index.html)\n[![Minimum PHP Version](https://img.shields.io/badge/php-%3E%3D%208.1-8892BF.svg?logo=php)](https://php.net/)\n\nAn OPCache preloader for CakePHP.\n\nReference: https://www.php.net/manual/en/opcache.preloading.php\n\nThis package is meant to provide an easy way for CakePHP application developers to generate preload\nfiles. Goals:\n\n- Generate an OPCache preloader with a simple command.\n- Allow optionally loading additional resources such as CakePHP plugins, userland app, and\ncomposer packages.\n- Provide a simplistic API for writing a custom preloader.\n\nFor an alternative approach, checkout [DarkGhostHunter/Preloader](https://github.com/DarkGhostHunter/Preloader).\n\nFor an OPCache UI, checkout [amnuts/opcache-gui](https://github.com/amnuts/opcache-gui).\n\nThe current release is for CakePHP 5 and PHP 8.1, see previous releases for older versions of CakePHP and PHP.\n\n| Version | Branch                                                         | Cake Version | PHP Version | \n|---------|----------------------------------------------------------------|--------------|-------------|\n| 1.*     | [main](https://github.com/cnizzardini/cakephp-preloader)       | ^5.0         | ^8.1        |\n| 0.*     | [v0](https://github.com/cnizzardini/cakephp-preloader/tree/v0) | ^4.2         | ^7.4        | \n\n## Installation\n\nYou can install this plugin into your CakePHP application using [composer](https://getcomposer.org).\n\nThe recommended way to install composer packages is:\n\n```console\ncomposer require cnizzardini/cakephp-preloader\n```\n\nNext, load the plugin: \n\n```shell\nbin/cake plugin load CakePreloader --only-cli\n```\n\nOr via manual steps in the CakePHP [plugin documentation](https://book.cakephp.org/5/en/plugins.html#loading-a-plugin).\n\n## Usage\n\nThe easiest way to use CakePreloader is via the console command. This command can easily be included as\npart of your applications build process.\n\n```console\n/srv/app $ bin/cake preloader --help\nGenerate a preload file\n\nUsage:\ncake preloader [options]\n\nOptions:\n\n--app           Add your applications src directory into the preloader\n--help, -h      Display this help.\n--name          The preload file path. (default: ROOT . DS . 'preload.php')\n--packages      A comma separated list of packages (e.g. vendor-name/package-name) to add to the preloader\n--plugins       A comma separated list of your plugins to load or `*` to load all plugins/*\n--cli           Should the preloader file exit when run via the php-cli? (default: true)\n--quiet, -q     Enable quiet output.\n--verbose, -v   Enable verbose output.\n```\n\nYou may also load configurations from a `config/preloader_config.php` file. Please note, **command line arguments take\nprecedence**. See [assets/preloader_config.php](assets/preloader_config.php) for a sample configuration file. If you \nprefer handling configurations another way read the CakePHP documentation on\n[loading configuration files](https://book.cakephp.org/5/en/development/configuration.html#loading-configuration-files).\n\n### Examples:\n\nDefault loads in CakePHP core files excluding TestSuite, Console, Command, and Shell namespaces. The preload file is \nwritten to `ROOT . DS . 'preload.php'`:\n\n```console\nbin/cake preloader\n```\n\nInclude a list of composer packages:\n\n```console\nbin/cake preloader --packages=cakephp/authentication,cakephp/chronos\n```\n\nInclude your `APP` code:\n\n```console\nbin/cake preloader --app\n```\n\nInclude all your projects plugins:\n\n```console\nbin/cake preloader --plugins=*\n```\n\nInclude a list of your projects plugins:\n\n```console\nbin/cake preloader --plugins=MyPlugin,MyOtherPlugin\n```\n\n### Before Write Event\n\nYou can extend functionality by listening for the `CakePreloader.beforeWrite` event. This is dispatched just before\nyour preloader file is written.\n\n```php\n(\\Cake\\Event\\EventManager::instance())-\u003eon('CakePreloader.beforeWrite', function(Event $event){\n    /** @var Preloader $preloader */\n    $preloader = $event-\u003egetSubject();\n    $resources = $preloader-\u003egetPreloadResources();\n    // modify resources or whatever...\n    $preloader-\u003esetPreloadResources($resources);\n});\n```\n\nFor more on events, read the CakePHP [Events System](https://book.cakephp.org/5/en/core-libraries/events.html#registering-listeners) documentation.\n\n### Preloader Class\n\nYou can customize your OPCache Preloader using the same class used by the console command. Preloader uses a port of \nCakePHP 4.x's Filesystem class under the hood.\n\n```php\nuse CakePreloader\\Preloader;\n\n$preloader = new Preloader();\n$preloader-\u003eloadPath('/required/path/to/files', function (\\SplFileInfo $file) {\n    // optional call back method, return true to add the file to the preloader\n    return true;\n});\n\n// default path is ROOT . DS . 'preload.php'\n$preloader-\u003ewrite('/optional/path/to/preloader-file.php');\n```\n\n## Performance:\n\nObviously, these types of benchmarks should be taken with a bit of a gain of salt. I benchmarked this using apache \nbench with this project here: https://github.com/mixerapi/demo which is a dockerized REST API \n(LEMP stack on alpine + php-fpm 8.0). CakePHP `DEBUG` was set to false.\n\n```ini\nextension=intl.so\nextension=pdo_mysql.so\nextension=sodium\nextension=zip.so\nzend_extension=opcache.so\n\n[php]\nsession.auto_start = Off\nshort_open_tag = Off\nopcache.preload_user=root\nopcache.preload=/srv/app/preload.php\nopcache.interned_strings_buffer = 16\nopcache.max_accelerated_files = 20000\nopcache.memory_consumption = 256\nopcache.enable_cli = 0\nopcache.enable = 1\nopcache.revalidate_freq = 360\nopcache.fast_shutdown = 1\nrealpath_cache_size = 4096K\nrealpath_cache_ttl = 600\n```\n\nNote: `opcache.preload_user=root` and `opcache.preload=/srv/app/preload.php` were disabled for the no preload run.\n\n| Type                      | JSON View (no db)      | JSON View (db select)   |\n|---------------------------|------------------------|-------------------------|\n| OPCache Only              | 892.69 [#/sec] (mean)  | 805.29 [#/sec] (mean)   |\n| OPCache Preload (default) | 1149.08 [#/sec] (mean) | 976.30 [#/sec] (mean)   |\n\n\nThis is 28% more requests per second for JSON responses and 21% more requests per second with JSON + simple SQL select \nwhen OPCache Preload is enabled.\n\n## Tests / Analysis\n\nTest Suite:\n\n```console\ncomposer test\n```\n\nTest Suite + Static Analysis:\n\n```console\ncomposer check\n```\n","funding_links":[],"categories":["Miscellaneous"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcnizzardini%2Fcakephp-preloader","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcnizzardini%2Fcakephp-preloader","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcnizzardini%2Fcakephp-preloader/lists"}