PHP 8.1.4 - Opcache 内存不足
几个小时后TTFB会增加,我一直在遇到麻烦。我最初认为这是由于IIS中的某些东西,但事实证明这实际上是Opcache。
我还注意到“手动重新启动”值不断增加。没有启动手动重新启动,我验证了我们的PHP脚本中没有此类呼叫。
配置:
- Windows Server 2022(在2016年服务器上也存在相同的行为)
- IIS 10
- php 8.1.4
- 96GB RAM
几个小时后,Opcache将其置于其错误日志中:
- 警告没有足够的免费共享空间来分配4176个字节(1856字节免费)
opcache_get_status opcache_get_status的输出spite慢/不使用opcache:
["opcache_enabled"]=> bool(true) ["cache_full"]=> bool(true) ["restart_pending"]=> bool(false) ["restart_in_progress"]=> bool(false) ["memory_usage"]=> array(4) { ["used_memory"]=> int(536869056) ["free_memory"]=> int(1856) ["wasted_memory"]=> int(0) ["current_wasted_percentage"]=> float(0) } ["interned_strings_usage"]=> array(4) { ["buffer_size"]=> int(50331160) ["used_memory"]=> int(3990280) ["free_memory"]=> int(46340880) ["number_of_strings"]=> int(53057) } ["opcache_statistics"]=> array(13) { ["num_cached_scripts"]=> int(0) ["num_cached_keys"]=> int(0) ["max_cached_keys"]=> int(65407) ["hits"]=> int(0) ["start_time"]=> int(1648533458) ["last_restart_time"]=> int(1648578530) ["oom_restarts"]=> int(0) ["hash_restarts"]=> int(0) ["manual_restarts"]=> int(232) ["misses"]=> int(11740) ["blacklist_misses"]=> int(0) ["blacklist_miss_ratio"]=> float(0) ["opcache_hit_rate"]=> float(0) } ["scripts"]=> array(0) { } ["jit"]=> array(7) { ["enabled"]=> bool(false) ["on"]=> bool(false) ["kind"]=> int(5) ["opt_level"]=> int(4) ["opt_flags"]=> int(6) ["buffer_size"]=> int(0) ["buffer_free"]=> int(0) }
在另一个网站上,输出相似,除了它显示OPCACHE现在已禁用了OPCACHE ,“ restart_pending”是正确的,但实际上从未重新启动。
["opcache_enabled"]=> bool(false) ["cache_full"]=> bool(false) ["restart_pending"]=> bool(true) ["restart_in_progress"]=> bool(false) ["memory_usage"]=> array(4) { ["used_memory"]=> int(284053552) ["free_memory"]=> int(252817360) ["wasted_memory"]=> int(0) ["current_wasted_percentage"]=> float(0) } ["interned_strings_usage"]=> array(4) { ["buffer_size"]=> int(50331160) ["used_memory"]=> int(3564656) ["free_memory"]=> int(46766504) ["number_of_strings"]=> int(53844) } ["opcache_statistics"]=> array(13) { ["num_cached_scripts"]=> int(724) ["num_cached_keys"]=> int(1353) ["max_cached_keys"]=> int(65407) ["hits"]=> int(134503) ["start_time"]=> int(1648551278) ["last_restart_time"]=> int(1648557365) ["oom_restarts"]=> int(0) ["hash_restarts"]=> int(0) ["manual_restarts"]=> int(20) ["misses"]=> int(1458) ["blacklist_misses"]=> int(0) ["blacklist_miss_ratio"]=> float(0) ["opcache_hit_rate"]=> float(98.9276336596524) } ["jit"]=> array(7) { ["enabled"]=> bool(false) ["on"]=> bool(false) ["kind"]=> int(5) ["opt_level"]=> int(4) ["opt_flags"]=> int(6) ["buffer_size"]=> int(0) ["buffer_free"]=> int(0) }
opcache设置(忽略调试记录模式 - 现在就打开它以查看它在失败时在做什么)
opcache.enable.enable = 1
opcache.enable_cli = 1
opcache.memory_consumption.memory_consumptir = 512
opcache.interned_buffer = 64 = 6444
opcache.max_accelerated_files = 50000
= 15
opcache.use_cwd = 1
= 0
= 2
opcache.revalidate_freq
opcache.validate_timestamps
opcache.max_wasted_percentage
ache_fallback = 0
opcache.file_update_protection = 0
I've been having trouble where TTFB would increase after a few hours. I initially thought it was due to something in IIS, but it turns out it's actually opcache.
I also noticed the "manual restarts" value keeps increasing. No manual restarts are initiated, and I verified no such call is present in our PHP scripts.
Configuration:
- Windows Server 2022 (same behavior was present on Server 2016 too)
- IIS 10
- PHP 8.1.4
- 96GB RAM
After a few hours, opcache places this in its error log:
- Warning Not enough free shared space to allocate 4176 bytes (1856 bytes free)
Output of opcache_get_status when site is slow/not using opcache:
["opcache_enabled"]=> bool(true) ["cache_full"]=> bool(true) ["restart_pending"]=> bool(false) ["restart_in_progress"]=> bool(false) ["memory_usage"]=> array(4) { ["used_memory"]=> int(536869056) ["free_memory"]=> int(1856) ["wasted_memory"]=> int(0) ["current_wasted_percentage"]=> float(0) } ["interned_strings_usage"]=> array(4) { ["buffer_size"]=> int(50331160) ["used_memory"]=> int(3990280) ["free_memory"]=> int(46340880) ["number_of_strings"]=> int(53057) } ["opcache_statistics"]=> array(13) { ["num_cached_scripts"]=> int(0) ["num_cached_keys"]=> int(0) ["max_cached_keys"]=> int(65407) ["hits"]=> int(0) ["start_time"]=> int(1648533458) ["last_restart_time"]=> int(1648578530) ["oom_restarts"]=> int(0) ["hash_restarts"]=> int(0) ["manual_restarts"]=> int(232) ["misses"]=> int(11740) ["blacklist_misses"]=> int(0) ["blacklist_miss_ratio"]=> float(0) ["opcache_hit_rate"]=> float(0) } ["scripts"]=> array(0) { } ["jit"]=> array(7) { ["enabled"]=> bool(false) ["on"]=> bool(false) ["kind"]=> int(5) ["opt_level"]=> int(4) ["opt_flags"]=> int(6) ["buffer_size"]=> int(0) ["buffer_free"]=> int(0) }
On another website, the output is similar, except it's showing opcache is now disabled, and "restart_pending" is true, but never actually restarts.
["opcache_enabled"]=> bool(false) ["cache_full"]=> bool(false) ["restart_pending"]=> bool(true) ["restart_in_progress"]=> bool(false) ["memory_usage"]=> array(4) { ["used_memory"]=> int(284053552) ["free_memory"]=> int(252817360) ["wasted_memory"]=> int(0) ["current_wasted_percentage"]=> float(0) } ["interned_strings_usage"]=> array(4) { ["buffer_size"]=> int(50331160) ["used_memory"]=> int(3564656) ["free_memory"]=> int(46766504) ["number_of_strings"]=> int(53844) } ["opcache_statistics"]=> array(13) { ["num_cached_scripts"]=> int(724) ["num_cached_keys"]=> int(1353) ["max_cached_keys"]=> int(65407) ["hits"]=> int(134503) ["start_time"]=> int(1648551278) ["last_restart_time"]=> int(1648557365) ["oom_restarts"]=> int(0) ["hash_restarts"]=> int(0) ["manual_restarts"]=> int(20) ["misses"]=> int(1458) ["blacklist_misses"]=> int(0) ["blacklist_miss_ratio"]=> float(0) ["opcache_hit_rate"]=> float(98.9276336596524) } ["jit"]=> array(7) { ["enabled"]=> bool(false) ["on"]=> bool(false) ["kind"]=> int(5) ["opt_level"]=> int(4) ["opt_flags"]=> int(6) ["buffer_size"]=> int(0) ["buffer_free"]=> int(0) }
Opcache settings (ignore the debug logging mode - just turned that on now to see what it's doing when it fails)
opcache.enable=1
opcache.enable_cli=1
opcache.memory_consumption=512
opcache.interned_strings_buffer=64
opcache.max_accelerated_files=50000
opcache.max_wasted_percentage=15
opcache.use_cwd=1
opcache.validate_timestamps=0
opcache.revalidate_freq=2
opcache.save_comments=1
opcache.error_log=opcache.log
opcache.log_verbosity_level=4
opcache.file_cache_fallback=0
opcache.file_update_protection=0
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论