php / php/php-src

Opcache prevents file from being added to realpath cache?

Open
#15,030 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Extension: opcache Status: Needs Triage
Dominant language
C
Stars
40.4k
Forks
8.1k
Avg merge
2d 13h
Merged PRs (30d)
96

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the behavior with foo.php and bar.php under php-fpm, using require_once, realpath_cache_get(), is_file(), realpath(), and clearstatcache() while opcache validation is enabled. Compare results across worker processes and trace the opcache and realpath-cache interaction; done means explaining the differing cache contents and the failure to repopulate the cache, or identifying a confirmed fix.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, php
Domain
backend, performance
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.