R
R
Roman Basharin2017-02-06 19:09:20
PHP
Roman Basharin, 2017-02-06 19:09:20

One composer autoloader (autoload.php) in the index file or several scattered around the project?

Greetings colleagues, I recently started working with the composer, but this issue is not addressed anywhere in the manuals. If I understand correctly, then the autoloader essentially just includes all files, taking into account dependencies, in the right order. Suppose we have several dozen libraries.
We include autoloader.php in the index file.
+ forget about including new libraries forever
- apparently with every simple request, where these libraries are not needed at all, we get an excessive load on the interpreter, due to the connection of megabytes of code (consider, if we have either weigh 1MB, then each request consumes 1MB of memory during processing , quite noticeable)
We create several composer.json scattered around the project and connect dependencies depending on the functionality of a particular module
+ only what is needed at the time of using this part of the script is connected in the code
- probably there are hemorrhoids with thinking through the architecture in this regard. There will be duplication of dependencies, perhaps there will be duplication when connecting via 'use {namespace}'
Actually, are there any best practices in this regard?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Sisyukin, 2017-02-06
@Hellek

As if there are 4 methods of autoload. This files described by you works like this, Takes and includes everything that you prescribed for him there.
In other ways, autoload will only work when needed. Walk through the script with debugging and you will immediately understand.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question