I'm using SF2 in one of our legacy project, not the entire framework but by pulling in bundles and components I need. And I have always wondered about these lines of code:
$loader = require_once __DIR__.'/../app/bootstrap.php.cache';
require_once __DIR__.'/../app/AppKernel.php';
//require_once __DIR__.'/../app/AppCache.php';
$kernel = new AppKernel('prod', false);
$kernel->loadClassCache();
I wonder what this bootstrap.php.cache file is for, what it is for, how it is generated (if I'm not using the SF2 whole framework). I didn't use it before, and there was no problem, but I wonder if this can give me some performance boost etc that I should look into. I tried to find all around but couldn't find a document dedicated to this subject.
To ensure optimal flexibility and code reuse, Symfony2 applications leverage a variety of classes and 3rd party components. But loading all of these classes from separate files on each request can result in some overhead. To reduce this overhead, the Symfony2 Standard Edition provides a script to generate a so-called bootstrap file, consisting of multiple classes definitions in a single file. By including this file (which contains a copy of many of the core classes), Symfony no longer needs to include any of the source files containing those classes. This will reduce disc IO quite a bit.
Source: Use Bootstrap Files.
From the Symfony documentation:
To ensure optimal flexibility and code reuse, Symfony2 applications leverage a variety of classes and 3rd party components. But loading all of these classes from separate files on each request can result in some overhead. To reduce this overhead, the Symfony2 Standard Edition provides a script to generate a so-called bootstrap file, consisting of multiple classes definitions in a single file. By including this file (which contains a copy of many of the core classes), Symfony no longer needs to include any of the source files containing those classes. This will reduce disc IO quite a bit.
You can generate your bootstrap file like this:
php vendor/sensio/distribution-bundle/Sensio/Bundle/DistributionBundle/Resources/bin/build_bootstrap.php
The bootstrap cache file can be an irritation during development because it changes the line numbers in stack traces. Fortunately it can be easily disabled in web/app_dev.php
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With