php / php/php-src

Opcache prevents file from being added to realpath cache?

未关闭
#15,030 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

Bug Extension: opcache Status: Needs Triage
主要语言
C
星标
40.4k
派生
8.1k
平均合并
2 天 13 小时
30 天内合并 PR
96

描述

Description

realpath cache is a per process cache
opcache is a shared cache

opcache is enabled with validation 2 seconds

foo.php contains:

<?php $t = time();

bar.php contains:

$path = '../foo.php';
require_once $path;
echo $t;

var_dump( realpath_cache_get() );

with php-fpm request bar.php multiple times.

when checking realpath_cache_get() we see foo.php is added to the realpath cache
as soon as opcache has cached this require once foo.php, foo.php is removed from realpath cache - for most worker processes.

Questions:

  1. opcache seems to be able to clear the realpath cache for some (?) workers - how is opcache able to do that? or does this happen on every request separately? (how come that foo.php is still in realpath cache for some workers though?)

  2. no matter what (is_file, realpath,...) calls with ../foo.php will never make it populate realpath cache again with this file, once it's in opcache - even when calling clearstatcache before it because the file is potentially deleted beforehand. It always seems to fetch the full path again from disk instead of storing it in realpath?

PHP Version

8.3

Operating System

No response

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

在启用 opcache 验证的情况下,使用 require_once、realpath_cache_get()、is_file()、realpath() 和 clearstatcache(),在 php-fpm 下通过 foo.php 和 bar.php 复现该行为。比较不同 worker 进程之间的结果,并跟踪 opcache 与 realpath-cache 之间的交互;当能够解释不同的缓存内容以及缓存未能重新填充的原因,或确定一个已确认的修复方案时,即视为完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
c, php
领域
backend, performance
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
需要澄清
新手友好度
30/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。