Joining PHP files into one only increases performance?


I have the impression that every time I run the dump-autoload command to generate autoload of classes via composer , a bootstrap/compiled.php file is created.

Inside it, there seems to be a tangle of classes and namespaces (it's as if they've linked multiple files into one).

Generate a PHP code where the classes used are in the same file would be "faster" than having them "scattered" in the directories?

asked by anonymous 14.07.2015 / 18:20

3 answers


Yes, it increases. So what?

First, it will be a minimal increase. Irrelevant in most, if not all cases. The gain will only be in the load. And you probably can not even measure it.

You probably do not need to have that gain. And if you need, there are many other things that are more important to improve performance.

Forget this, think about the organization.

It's obvious that the less disk access, the better. But if this is used little makes no difference, if it is used a lot it will already be in the operating system cache and the difference will be close to zero.

You'll have better benefit if you use a default language code caching system or third-party .

I do not know exactly what you're doing, but it's probably all in one file because it was not meant for a human to read, it does not have to be organized, so it's easier to do that. It does not put everything together because of the performance.

14.07.2015 / 18:25

Generate a PHP code in which the classes used are in the same   file would be "faster" than having them "scattered" by the   directories?

Theoretically running a single file decreases disk access, which does not need to fetch through several other files.

But worrying about this can be an early optimization, because when using OpCache , which comes by default from PHP 5.5+ , but deactivated, it caches the files in memory and the I / The one already dies there.


I have the impression that every time I run the command   dump-autoload to generate autoload classes via composer, a   bootstrap / compiled.php file is created.

Composer does not generate the compiled.php file when running dump-autoload , this command only regenerates the autoloaders from the vendor\composer folder from what is set in the composer.json of the project.

You should be confusing this file with Laravel php artisan otimize , which uses a library to generate this automatically compiled file for join framework classes, which can bring more problems than helping .

In short: do not worry about it. In production environments enable PHP OpCache and be happy.

More about OpCache you can read here at .

14.07.2015 / 19:13

Yes, it boosts performance, but the final result is ridiculous, not really worth the trouble.

Well, you should remember that in the future you need to take the minification you've done in the code, and since any PHP system is more than 1 file, you'll have a lot of work for a derisory performance difference like I said earlier.

If you want to better understand how PHP performs on your systems, try to study how memory allocation works and variable types, so you can start coding and typing (even if it is not a common practice in PHP) its variables and thus prevent a variable from having a larger allocation than it should in memory.

05.01.2017 / 14:02