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 r包runway详细安装教程
  • ¥15 Html中读取Json文件中数据并制作表格
  • ¥15 谁有RH342练习环境
  • ¥15 STM32F407 DMA中断问题
  • ¥15 uniapp连接阿里云无法发布消息和订阅
  • ¥25 麦当劳点餐系统代码纠错
  • ¥15 轮班监督委员会问题。
  • ¥20 关于变压器的具体案例分析
  • ¥15 生成的QRCode圖片加上下載按鈕
  • ¥15 板材切割优化算法,数学建模,python,lingo