定制 ez-php/opcache 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

ez-php/opcache

Composer 安装命令:

composer require ez-php/opcache

包简介

OPcache preload script generator for the ez-php framework — scans class paths and writes a ready-to-use preload.php

README 文档

README

OPcache preload script generator for the ez-php framework.

Scans configured class directories and generates a ready-to-use preload.php that can be referenced by PHP's opcache.preload ini directive. Preloading compiles framework classes into shared memory at server startup, eliminating per-request file I/O and compilation overhead.

Installation

composer require ez-php/opcache

Registration

Add the service provider in provider/modules.php:

$app->register(\EzPhp\OPCache\PreloaderServiceProvider::class);

Configuration

Add config/opcache.php:

<?php

return [
    // Absolute path for the generated preload script.
    'output_file' => base_path('preload.php'),

    // Directories to scan for PHP files.
    'paths' => [
        base_path('vendor/ez-php/framework/src'),
        base_path('vendor/ez-php/contracts/src'),
        base_path('app'),
    ],

    // Filename glob patterns to exclude.
    'exclude' => [
        '*Test.php',
        '*TestCase.php',
        '*Interface.php',
    ],

    // Set to true to use require_once instead of opcache_compile_file.
    // Useful when classes have cross-file dependencies that must be resolved
    // in the correct order. Defaults to false.
    'require_once' => false,
];

Generating the preload script

Use the Preloader directly — for example from a Composer script or a deploy step:

use EzPhp\OPCache\PreloadConfig;
use EzPhp\OPCache\Preloader;

$config = new PreloadConfig(
    outputFile: '/var/www/html/preload.php',
    paths: [
        '/var/www/html/vendor/ez-php/framework/src',
        '/var/www/html/vendor/ez-php/contracts/src',
    ],
    excludePatterns: ['*Test.php', '*TestCase.php'],
);

$count = (new Preloader($config))->generate();

echo "Generated preload script with {$count} files.\n";

Or resolve it from the container after bootstrapping the application:

$preloader = $app->make(\EzPhp\OPCache\Preloader::class);
$count = $preloader->generate();

Enabling preloading in php.ini

After generating the script, point PHP to it:

opcache.preload=/var/www/html/preload.php
opcache.preload_user=www-data

Restart PHP-FPM or the web server after each change to the preload script.

Generated script format

<?php

// Auto-generated OPcache preload script.
// Generated by ez-php/opcache at 2026-03-29 12:00:00
// Total files: 42
// Usage: set opcache.preload=<this-file> in php.ini

if (function_exists('opcache_compile_file')) {
    opcache_compile_file('/var/www/html/vendor/ez-php/framework/src/Application.php');
    opcache_compile_file('/var/www/html/vendor/ez-php/framework/src/Container.php');
    // ...
}

Testing

No external services required — all tests run in-process using temporary directories.

composer test

License

MIT

ez-php/opcache 适用场景与选型建议

ez-php/opcache 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 03 月 29 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「framework」 「performance」 「php」 「Opcache」 「preloading」 「ez-php」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 ez-php/opcache 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 ez-php/opcache 我们能提供哪些服务?
定制开发 / 二次开发

基于 ez-php/opcache 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 37
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-03-29