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?
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