Skip to content

opcache.use_cwd has no effect (when used with file_cache?) #17769

@kkmuffme

Description

@kkmuffme

Description

The following code:

/foo/test.php

<?php

function foo() {
    echo "hello" . PHP_EOL;
}

foo();

/bar/test.php

<?php

function foo() {
    echo "world" . PHP_EOL;
}

foo();

Run:

cd /foo
php -d opcache.enable_cli=1 -d opcache.jit=disable -d opcache.file_cache=/tmp/opcache -d opcache.use_cwd=0 test.php
cd /bar
php -d opcache.enable_cli=1 -d opcache.jit=disable -d opcache.file_cache=/tmp/opcache -d opcache.use_cwd=0 test.php

Resulted in this output:

hello
world

But I expected this output instead:

hello
hello

In fact the output makes sense, what doesn't make sense is opcache.use_cwd since the files are stored with an absolute path in /tmp/opcache anyway.

  1. does "use_cwd" only have an effect for opcache in memory? If yes, why does the file_cache store everything with absolute paths but in memory not?

  2. what if chdir() is called in the PHP script? When opcache.use_cwd=1 (default) is used this would mean that things that are in opcache already won't be used since cwd changed? Or does cwd only refer to the directory from which the PHP service is (re)started from? (which would have some quite funny side-effects)

Depending on the answer, this would possibly imply that opcache.use_cwd should be default 0 when used with the CLI SAPI.

Also, this matters especially when calling opcache_compile_file(...) with opcache.use_cwd=1 (default) as well as for opcache.preload

EDIT: or do opcache_compile_file() and opcache.preload only populate the memory, but not the file cache?
What if file cache exists and opcache.preload is used - will things from file cache be used or from opcache.preload?

PHP Version

8.4 (same in 8.3 and probably before)

Operating System

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions