dsft8327 2013-12-02 20:32
浏览 33

如何在Symfony 2中只使用一个文件作为Doctrine注释阅读器缓存?

I'm working on a Symfony 2 project running on a shared hosting (cheap but slow, I've to admit). Performances are really bad, even minifying all css/js and enabling the gzip compression (PHP output only with a custom php.ini). Server responds in 5-10 seconds, that is the time to parse and execute PHP files. Dowloading resources takes just millisecs, hence the delay is between the request and response. This is what (I think) I've found with the Chrome network console.

Looking at the annotation reader cache folder (app/cache/prod/annotations) I've noticed that and there are 441 *.cache.php files in it. I think that the annotations reader is going to read all of these files on each request!

This could be the source of the bad performances. How can I speed up things and write a custom annotation cache driver that uses just less files or a single file as annotations cache?

  • 写回答

1条回答 默认 最新

  • duanji2014 2013-12-02 22:19
    关注

    Merging annotation cache files into one won't speed up things, moreover, it will slow them down. I've got an explanation for this statement.

    First of all if you check the Annotation cache (file)reader source

    82: public function getClassAnnotations(\ReflectionClass $class) {
    
     ....
    
       $path = $this->dir.'/'.strtr($key, '\\', '-').'.cache.php';
       if (!is_file($path)) {
           $annot = $this->reader->getClassAnnotations($class);
           $this->saveCacheFile($path, $annot);
           return $this->loadedAnnotations[$key] = $annot;
       }
    
     ....
    
    return $this->loadedAnnotations[$key] = include $path;
    

    So, basically, what happens here is that every file is annotation content of specific class. It's a simple small file being fetched and ready for use. If it's not there, cache is being 'slowly' generated manually and getting saved for future use.

    If you want this driver dump cache into one file, then instead of:

    include $path;
    

    you'll have to do something like:

    file_get_contents('one_big_cache');
    ...searching/regexps/arrays/loops...
    return $result;
    

    And this looks way slower if you ask me.

    I'm not claiming to be absolutely right on this one and will be glad to hear opinions on this topic

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog