Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Why do Phalcon scan in directories even the class is directly "told" to it?

I know that ->registerDirs is slow, because Phalon then needs to iterate through all directories to load a class. But I found out that even I directly register via ->registerClasses, the loading is still slow. (I know because Im using virtualbox, and its slow). BUT if I remove ->registerDirs - voila! Its superfast!



33.6k
Accepted
answer

registerDirs is slow because for every directory registered it tries to stat the file to see if the file is there. My recommendation is using the namespace strategy.



11.3k

thats okay, but I still dont understand why to. Anyway, thanks Master :)

// Register global classes using Loader classes strategy
//This is the fastest method of autoloading
$loader->registerClasses(
    [
        'AAFV\Constants' => $config->application->constantsFile,
        'AAFV\Routes' => $config->application->routesFile,
        'AAFV\ErrorHandler' => $config->application->controllersDir . $config->application->errorHandler
    ]
);