We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Autoloader, get all classes and their path

so, by Loader, I register some classes directly. I also register dirs - but this is not so good for performance, since Phalcon will have to look for classes through these paths too, as written in the document. So, I want to do the following: geting all classes and write them into an array, and then manually pass this array to the Phalcon telling to it what classes where is. How to do this?

Composer supports this optimalization

https://mouf-php.com/optimizing-composer-autoloader-performance

Phalcons Loader is PSR-0 and PSR-4 compliant and does't support something like array dump. If you are using Opcache your performance boost will be minimal with optimized autoload because majority of PHP files will be served from cache.

Where would your array come from? If you plan to scan a directory and populate it from there, your performance will be even worse. If you specifiy them manually, why not simply use Loader::registerClasses()?

As @David said, by using opcache and the factory loader mechanism (either Phalcon or Composer), you'll get the best performance/flexibility ratio.

edited Mar '16

Remember that you can register namespaces also. I think its best option, this way you can register many classes.



28.2k

Bencze, I would have scan once and then cache. Say, an class => path array