Open
Description
Description
The following code:
❯ mkdir -p /tmp/.opcache && php -d opcache.enable_cli=1 -d opcache.file_cache=/tmp/.opcache -d opcache.file_cache_only=1 -r "var_dump(opcache_get_status());"
Resulted in this output:
array(3) {
["opcache_enabled"]=>
bool(false)
["file_cache"]=>
string(13) "/tmp/.opcache"
// ...
}
But I expected this output instead:
array(10) {
["opcache_enabled"]=>
bool(true)
["file_cache"]=>
string(13) "/tmp/.opcache"
// ...
}
Note that without opcache.file_cache_only
the output is correct:
❯ mkdir -p /tmp/.opcache && php -d opcache.enable_cli=1 -d opcache.file_cache=/tmp/.opcache -r "var_dump(opcache_get_status());"
array(10) {
["opcache_enabled"]=>
bool(true)
["file_cache"]=>
string(13) "/tmp/.opcache"
// ...
}
Context
Overall context: I have a short-living container that runs a script (that is doing computations) and I wanted to experiment warming up opcache before so I could speed up the script execution.
I tried the following setup:
<?php
// opcache_compile.php
// This is assuming composer install --classmap-authoritative
declare(strict_types=1);
use Composer\Autoload\ClassLoader;
$loader = include 'vendor/autoload.php';
assert($loader instanceof ClassLoader);
foreach ($loader->getClassMap() as $file) {
opcache_compile_file($file);
}
# Dockerfile
FROM php:8.4-cli-alpine
COPY --from=builder /opt/app /opt/app
RUN docker-php-ext-install opcache \
&& mkdir /opt/app/.opcache \
&& /usr/local/bin/php -d opcache.enable_cli=1 -d opcache.file_cache=/opt/app/.opcache -d opcache.file_cache_only=1 /opt/app/opcache_compile.php
ENTRYPOINT ["/opt/app/bin/run.sh"]
With the expectation of running it with
docker run --rm app /usr/local/bin/php -d opcache.enable_cli=1 -d opcache.file_cache=/opt/app/.opcache -d opcache.file_cache_only=1 /opt/app/app.php
PHP Version
PHP 8.3.6 (cli) (built: Mar 19 2025 10:08:38) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.6, Copyright (c) Zend Technologies
with Zend OPcache v8.3.6, Copyright (c), by Zend Technologies
Operating System
Ubuntu 24.04