optimize-docker-opcache
安装方式
先用 Prompt 核对来源与依赖。也可下载安装包。
用 AI 助手安装
复制提示词,让助手先核对固定版本和依赖。
查看 Prompt收起 Prompt
先检查当前 Agent 是否已安装 SkillPI Skill Finder。如果尚未安装,请按官方仓库的说明安装并启用:https://github.com/Findskills/skillpi。然后使用 Skill Finder 打开此 SkillPI 详情页并定位 "optimize-docker-opcache":https://skillpi.com/zh/skills/deepskill-67a6d0026018df8da6838406f90d29bf8da122369b6d1300b36222b286e4ed02。安装前核对上游来源和版本:https://github.com/dykyi-roman/awesome-claude-code。来源不一致时停止并说明差异。核对通过后,用 Skill Finder 安装目标 Skill,并报告安装路径和来源版本。
来源与配置
github.com
配置方式待核实
请查看原始来源中的适用工具、依赖和权限要求。
安装实测待补充
优化 PHP Docker 容器的 OPcache 配置。为生产和开发环境提供 OPcache 的内存、文件限制、JIT 与验证等参数建议,便于在不同环境中调整性能与稳定性。
介绍来源: third_party · dykyi-roman · 0.0.1 参考来源
SkillPi 解读
- 能完成的任务
- 翻译待完成,请参阅来源文档。
- 实测状态
- 未测试
文件浏览
Frontmatter
name: optimize-docker-opcache
description: Optimizes OPcache configuration for PHP Docker containers. Configures memory, file limits, JIT, and validation for production and development.OPcache Configuration Optimization
Provides production and development OPcache tuning for PHP Docker containers, including JIT and preloading.
OPcache Impact Overview
┌─────────────────────────────────────────────────────────────────┐
│ OPCACHE PERFORMANCE IMPACT │
├─────────────────────────────────────────────────────────────────┤
│ Without OPcache: │
│ Request → Parse → Compile → Execute → Response ~50ms │
│ With OPcache: │
│ Request → Execute (cached bytecode) → Response ~15ms │
│ With OPcache + JIT: │
│ Request → Execute (native code) → Response ~10ms │
│ With OPcache + JIT + Preload: │
│ Request → Execute (preloaded) → Response ~5ms │
└─────────────────────────────────────────────────────────────────┘
Production vs Development Settings
| Setting | Production | Development | Purpose |
|---|---|---|---|
| opcache.enable | 1 | 1 | Enable OPcache |
| opcache.enable_cli | 1 | 0 | Cache for CLI scripts |
| opcache.memory_consumption | 256 | 128 | Shared memory (MB) |
| opcache.interned_strings_buffer | 32 | 16 | Interned strings (MB) |
| opcache.max_accelerated_files | 20000 | 10000 | Max cached files |
| opcache.validate_timestamps | 0 | 1 | Check file changes |
| opcache.revalidate_freq | 0 | 2 | Revalidation interval (s) |
| opcache.jit | 1255 | disable | JIT mode |
| opcache.jit_buffer_size | 128M | 0 | JIT buffer |
Memory Consumption Calculation
memory_consumption = total_php_files * avg_bytecode_size (20-50 KB per file)
Small project (500 files): 15MB → set 64MB
Medium project (2000 files): 60MB → set 128MB
Large project (5000 files): 175MB → set 256MB
Enterprise (10000+ files): 350MB → set 512MB
max_accelerated_files Calculation
PHP rounds up to the next prime from: 223, 463, 983, 1979, 3907, 7963, 16229, 32531, 65407, 130987
| Total PHP Files | Set To | PHP Uses |
|---|---|---|
| < 200 | 1000 | 983 |
| 200-900 | 4000 | 3907 |
| 900-3800 | 8000 | 7963 |
| 3800-8000 | 20000 | 16229 |
| 8000-16000 | 32531 | 32531 |
JIT Configuration (PHP 8.0+)
opcache.jit = CRTO (4-digit mode)
C: CPU optimization (0=off, 1=on)
R: Register allocation (0=off, 1=local, 2=global)
T: Trigger (0=first run, 3=hot counter, 5=tracing)
O: Optimization (0=none, 5=full)
| Mode | Value | Use Case |
|---|---|---|
| Tracing (recommended) | 1255 | Web applications |
| Function | 1205 | Simpler, less memory |
| Disabled | disable | Development, debugging |
Preloading (PHP 7.4+)
<?php
// config/preload.php
$directories = [
'/app/src/Domain/', '/app/src/Application/',
'/app/vendor/symfony/http-kernel/',
];
foreach ($directories as $dir) {
if (!is_dir($dir)) continue;
$it = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($dir, FilesystemIterator::SKIP_DOTS)
);
foreach ($it as $file) {
if ($file->getExtension() === 'php') opcache_compile_file($file->getRealPath());
}
}
| Category | Preload? | Reason |
|---|---|---|
| Domain entities / Value objects | Yes | Loaded on every request |
| Framework core | Yes | Always loaded |
| Controllers | Maybe | Only relevant routes |
| Tests / Migrations | No | Not in production |
Monitoring OPcache
| Metric | Healthy | Action Needed |
|---|---|---|
| Hit rate | > 99% | < 95%: check validate_timestamps |
| Memory free | > 20% | < 10%: increase memory_consumption |
| Wasted memory | < 5% | > 10%: restart PHP-FPM |
| Cache full | false | true: increase max_accelerated_files |
Production OPcache INI
[opcache]
opcache.enable = 1
opcache.enable_cli = 1
opcache.memory_consumption = 256
opcache.interned_strings_buffer = 32
opcache.max_accelerated_files = 20000
opcache.validate_timestamps = 0
opcache.revalidate_freq = 0
opcache.save_comments = 1
opcache.fast_shutdown = 1
opcache.jit = 1255
opcache.jit_buffer_size = 128M
opcache.preload = /app/config/preload.php
opcache.preload_user = www-data
opcache.log_verbosity_level = 1
opcache.error_log = /proc/self/fd/2
Development OPcache INI
[opcache]
opcache.enable = 1
opcache.enable_cli = 0
opcache.memory_consumption = 128
opcache.interned_strings_buffer = 16
opcache.max_accelerated_files = 10000
opcache.validate_timestamps = 1
opcache.revalidate_freq = 2
opcache.save_comments = 1
opcache.jit = disable
opcache.jit_buffer_size = 0
Dockerfile Integration
ARG APP_ENV=production
COPY docker/php/opcache-${APP_ENV}.ini /usr/local/etc/php/conf.d/opcache.ini
COPY config/preload.php /app/config/preload.php
Before/After Comparison
| Metric | No OPcache | OPcache | OPcache+JIT+Preload |
|---|---|---|---|
| First request | 200ms | 200ms | 50ms (preloaded) |
| Subsequent requests | 200ms | 15ms | 5ms |
| Memory per worker | 30MB | 35MB | 38MB |
| Throughput (req/s) | 50 | 300 | 500 |
| CPU usage | High | Medium | Low |
Generation Instructions
- Count PHP files:
find /app -name "*.php" | wc -l(including vendor) - Calculate memory: files * 35KB, round up to nearest power of 2
- Set max_accelerated_files: Next prime above file count
- Configure JIT: 1255 for production, disable for development
- Create preload script: Include domain, application, and framework core
- Set validate_timestamps: 0 for immutable containers, 1 for development
- Monitor: Check hit rate and memory usage after deployment
当前收录版本
0.0.1
质量评测
满分100 · 来自 SkillPi LAB 实验室的评测报告。
亮点
- 直接解决PHP Docker容器OPcache配置的核心痛点,显著提升性能
- 提供生产和开发环境的完整配置方案
- 包含详细的内存计算和文件数量估算方法
亮点
- 触发词精准完整,覆盖生产和开发环境
- 边界清晰,不会与其他Skill重叠
- description位置正确且内容完整
亮点
- Phase/步骤清晰,有出口条件
- 含端到端示例,frontmatter完整
- 单文件≤500行,结构良好
亮点
- 工具来源明确,参数正确
- 覆盖主要异常,不可逆操作有确认机制
- 提供监控指标和健康检查建议
取前四项原始分值的算术平均,四舍五入取整。可通过收录报告核对各项评分与说明,运行记录需单独查证。
正文静态检测
100 / 100 · skillpi-20261123-no-r3-v1
正文未命中当前规则。
分数仅反映正文中的规则命中,供使用前参考。附件与运行行为不在此评分范围内。
权限与使用前检查
根据当前主文档自动整理,命中内容可能是示例或防护说明;不是实际权限声明,也未覆盖附件、外部依赖或运行行为。
未从主文档识别到上述常见操作,不能据此判断无需权限或没有风险。
安全评级与访问范围
safe · 静态证据核验,不代表运行安全保证。
使用前请由宿主核对并授权实际文件读写、外部服务和联网目的地;本站的核验不会授予任何运行权限。
用户讨论
还没有已核实的点评。