我正在尝试在 Platform.sh 的 PHP8 上运行的 Symfony 5.4 上设置 Opcache 预加载,并遇到致命错误。
配置
必要的部分包括:
// platform.app.yaml
...
variables
php
'opcache.preload': 'var/cache/prod/App_KernelProdContainer.php'
...
hooks:
build: |
...
composer dump-autoload --no-dev --classmap-authoritative
deploy: |
...
sv restart app
...
我可以验证App_KernelProdContainer.php
文件是在上面配置中定义的正确位置创建的:
<?php
// This file has been auto-generated by the Symfony Dependency Injection Component for internal use.
if (\class_exists(\ContainerF9HiXre\App_KernelProdContainer::class, false)) {
// no-op
} elseif (!include __DIR__.'/ContainerF9HiXre/App_KernelProdContainer.php') {
touch(__DIR__.'/ContainerF9HiXre.legacy');
return;
}
if (!\class_exists(App_KernelProdContainer::class, false)) {
\class_alias(\ContainerF9HiXre\App_KernelProdContainer::class, App_KernelProdContainer::class, false);
}
return new \ContainerF9HiXre\App_KernelProdContainer([
'container.build_hash' => 'F9HiXre',
'container.build_id' => '98091d49',
'container.build_time' => 1644501054,
], __DIR__.\DIRECTORY_SEPARATOR.'ContainerF9HiXre');
包含的文件ContainerF9HiXre/App_KernelProdContainer.php
会在使用语句上引发错误,如下所示:
Fatal error: Uncaught Error: Class "Symfony\Component\DependencyInjection\Container" not found in /app/var/cache/prod/ContainerF9HiXre/App_KernelProdContainer.php:17
Stack trace:
#0 /app/var/cache/prod/App_KernelProdContainer.php(7): include()
#1 {main}
thrown in /app/var/cache/prod/ContainerF9HiXre/App_KernelProdContainer.php on line 17
包含文件中的使用语句如下所示:
namespace ContainerF9HiXre;
use Symfony\Component\DependencyInjection\Argument\RewindableGenerator;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
use Symfony\Component\DependencyInjection\Exception\LogicException;
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;