Frogg logo

Frogg's web tools

Hand Crafted Tools

Home > Coding PHP > PSR Librairies from composer
Welcome on Frogg's web tools | Current date :
11/12/2018
@@@WORK@@@
@@@WORK@@@
@@@WORK@@@

PSR Librairies from composer

PSR-4 Autoloader

Install PSR-4 Autoloader

copy to clipboard
{
    "autoload": 
		{
			"psr-4": { "App\\": "src/" }
		}
}

Include in PHP file

copy to clipboard
require('vendor/autoload.php');

Autoloader Optimization

By default, the Composer autoloader runs relatively fast. However, due to the way PSR-4 and PSR-0 autoloading rules are set up, it needs to check the filesystem before resolving a classname conclusively. This slows things down quite a bit, but it is convenient in development environments because when you add a new class it can immediately be discovered/used without having to rebuild the autoloader configuration.

The problem however is in production you generally want things to happen as fast as possible, as you can simply rebuild the configuration every time you deploy and new classes do not appear at random between deploys.

For this reason, Composer offers a few strategies to optimize the autoloader.

The offical post can be found here : autoloader optimization
Page created by the 18/02/2018 19:46
Generated in 0.034 sec & displayed in ... sec