Skip to content

opcache.revalidate_path and opcache.use_cwd noop? #4583

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
kkmuffme opened this issue Apr 3, 2025 · 1 comment
Open

opcache.revalidate_path and opcache.use_cwd noop? #4583

kkmuffme opened this issue Apr 3, 2025 · 1 comment
Labels
bug Documentation contains incorrect information Status: Needs Triage

Comments

@kkmuffme
Copy link

kkmuffme commented Apr 3, 2025

Description

The following code:

It's unclear what exactly the difference between opcache.revalidate_path and opcache.use_cwd is and it seems they're noop (in CLI?)?
Assuming php.ini has: include_path=/dev/null

/foo/safe.php
/bar/safe.php

<?php
function run() {
    echo __FILE__;
}

/foo/x.php
/bar/y.php

<?php
include 'safe.php';

/test.php

<?php
require __DIR__ . '/foo/x.php';
require __DIR__ . '/bar/y.php';

run();

php -dopcache.enable_cli=1 -dopcache.revalidate_path=0 -dopcache.use_cwd=0 test.php

Resulted in this output:

Cannot redeclare run()

But I expected this output instead:

/foo/safe.php

Changing /foo/x.php or /bar/y.php to

<?php
opcache_compile_file('safe.php');

has the same issue too.

According to php/php-src#17769 (comment) this shouldn't result in a fatal, because the provided path is the same for both, so it shouldn't even attempt to load the other

Also it's not entirely clear what the difference between these 2 directives actually is, based on a practical example.

PHP Version

PHP 8.4

Operating System

No response

@kkmuffme kkmuffme added bug Documentation contains incorrect information Status: Needs Triage labels Apr 3, 2025
@iluuu1994
Copy link
Member

Opcache uses the the string that the user passed to require as a key in the script map. opcache.use_cwd incorporates the current working directory into this key. This is mostly needed for shared hosting, i.e. where different projects may use the same path name relative to the cwd, pointing to different files. It's also worth noting opcache.use_cwd has no effect for absolute files. This settings is enabled by default.

opcache.revalidate_path on the other hand actually opens the file to use the resolved path as a key. This indeed makes opcache.use_cwd redundant. However, it will be even slower, but also more accurate. It may make a difference for symlinks (avoiding duplicate compilation), or multiple include_paths where the files are created dynamically (e.g. script from 2nd path was compiled and cached, script is created in 1st path, repeated inclusion will stick with 2nd path).

Does this resolve your questions? I agree that this may be documented better. I'll move it to the documentation bug tracker.

@iluuu1994 iluuu1994 transferred this issue from php/php-src Apr 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Documentation contains incorrect information Status: Needs Triage
Projects
None yet
Development

No branches or pull requests

2 participants