我们需要将缓存和日志文件存储在项目文件夹结构之外。我已经设置了parameters_prod.yml和parameters_dev.yml,它们将在部署到不同的服务器/环境时由竹子构建。
有没有办法在AppKernal中访问这些参数,以便在getCacheDir()函数中使用它们?这将是做事情的简单方法,而不是自己解析它们或其他什么。
因此,除了缓存和日志之外,最终的目录结构应该与默认的Symfony目录结构相同。服务器团队要求缓存和日志应该在var/tmp和var/logs下。因此,对于应用程序,缓存将是/var/tmp/symfony/projectName/prod和/var/tmp/symfony/projectName/dev。日志将遵循类似的结构。
因此,除了/var/www/ Symfony /projectName/var/cache变成/var/tmp/symfony/projectName和/var/www/Symfony/projectName/var/logs变成/var/logs/projectName之外,基本上结构将遵循普通symfony结构。请注意,这里的所有这些位置都是绝对的(项目根目录的位置可能会略有不同,在部署竹子时,它将设置正确的路径等)。
奇怪的是,当我像这样设置它时,站点实际上运行了,但我在新的缓存位置下看不到任何东西(还没有开始在日志端工作)。所以一定有缓存文件在某个地方,但是定位甚至找不到它们!
注意:我现在发现,如果您运行内部服务器,则不会发生此问题。只有当您在Apache下加载站点时,才会发生这种情况。
发布于 2016-10-28 17:35:14
您的想法的问题是,服务容器和参数在ConfigCache对象构建后立即进行初始化,并使用绝对缓存路径作为参数。
namespace Symfony\Component\HttpKernel;
...
/**
* The Kernel is the heart of the Symfony system.
*
* It manages an environment made of bundles.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
abstract class Kernel implements KernelInterface, TerminableInterface
{
...
/**
* Initializes the service container.
*
* The cached version of the service container is used when fresh, otherwise the
* container is built.
*/
protected function initializeContainer()
{
$class = $this->getContainerClass();
// !!!!!! cache config object construction
$cache = new ConfigCache($this->getCacheDir().'/'.$class.'.php', $this->debug);
$fresh = true;
if (!$cache->isFresh()) {
$container = $this->buildContainer();
$container->compile();
$this->dumpContainer($cache, $container, $class, $this->getContainerBaseClass());
$fresh = false;
}
require_once $cache->getPath();
$this->container = new $class();
$this->container->set('kernel', $this);
if (!$fresh && $this->container->has('cache_warmer')) {
$this->container->get('cache_warmer')->warmUp($this->container->getParameter('kernel.cache_dir'));
}
}
}因此,您不能访问getCacheDir()方法中的自定义参数。
你能重写getCacheDir()方法吗?
假设您的目录结构如下所示
-home
--symfony_app
--custom_cache_directory那么方法重写看起来就像这样:
public function getCacheDir()
{
return dirname(__DIR__).'/../custom_cache_directory/cache/'.$this->getEnvironment();
}更多信息请访问官方文档:http://symfony.com/doc/current/configuration/override_dir_structure.html#override-the-cache-directory
发布于 2016-11-01 12:58:37
所以答案是按照Matko的建议去做,不要使用/var/tmp目录。
因此,在/appName/app/AppKernel.php中,我编辑了getCacheDir(),使其看起来更像:
public function getCacheDir()
{
return '/var/symfony/cache/projectName' . '/' . $this->getEnvironment();
}或您想要使用的任何路径。
不要使用/tmp或/var/tmp (我在RHEL上)下的任何内容,因为这些文件夹会做一些奇怪的事情(/var/tmp似乎从未真正将缓存写入磁盘)。
https://stackoverflow.com/questions/40297985
复制相似问题