Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the purpose of the Symfony2 bootstrap.php.cache file?

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.

like image 626
mr1031011 Avatar asked Oct 19 '12 12:10

mr1031011


3 Answers

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.

like image 62
Elnur Abdurrakhimov Avatar answered Nov 04 '22 03:11

Elnur Abdurrakhimov


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
like image 37
Juan Sosa Avatar answered Nov 04 '22 02:11

Juan Sosa


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.

like image 2
Tamlyn Avatar answered Nov 04 '22 02:11

Tamlyn