【问题标题】:Using Redis for Symfony /var/cache and /var/logs将 Redis 用于 Symfony /var/cache 和 /var/logs
【发布时间】:2017-06-28 00:59:38
【问题描述】:

我正在 Homestead 中使用 PHP 7.1 运行 Symfony 3.* 实例,最近由于 NFS 同步变得疯狂并大大降低了整个安装的性能,我将缓存和日志目录从我的主文件夹中切换了出来。

我想知道是否可以通过配置或解决方法以某种方式将通常转到 ./var/ 的日志记录和缓存完全分派到 Redis?

【问题讨论】:

    标签: caching redis symfony homestead


    【解决方案1】:

    您可以修改日志记录以将其关闭或关闭 - 或选择不将其写入文件,而是将其发送到 Redis 或其他来源。 Monolog 可以使用许多可选目标,通常带有支持库和配置。

    缓存文件并非设计为写入其他地方。因为它们正在被写入磁盘,所以它们可以被 OpCache 缓存。

    但这并不意味着var/* 必须写入真实磁盘。如果您有共享内存,则可以用作 ram-disk(也称为 tmpfs)。应用程序可以很容易地更改为使用它 - 用于缓存和/或日志文件:

    class AppKernel extends Kernel
    {
        // ...
    
        public function getCacheDir()
        {
            if (in_array($this->environment, array('dev', 'test'))) {
                return '/dev/shm/appname/cache/' .  $this->environment;
            }
            return parent::getCacheDir();
        }
    
        public function getLogDir()
        {
            if (in_array($this->environment, array('dev', 'test'))) {
                return '/dev/shm/appname/logs';
            }
            return parent::getLogDir();
        }
    }
    

    来源:http://www.whitewashing.de/2013/08/19/speedup_symfony2_on_vagrant_boxes.html 通过https://stackoverflow.com/a/10784563

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-10-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-08-17
      • 2018-03-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多