Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Zend Framework 2: Composer\Autoload\includeFile is slow

According to New Relic transaction tracer, sometimes Composer\Autoload\includeFile takes around 318 ms to load my project.

I have dumped a classmap from composer, but still no difference it made.

composer.json requires the following:

"require": {
        "php": ">=5.3.3",
        "zendframework/zendframework": "2.4.*",
        "zendframework/zendservice-amazon": "2.*",
        "wisembly/elephant.io": "~3.0",
        "knplabs/github-api": "~1.2"
    }

I only have one module in my ZF2 application.

How can my ZF2 autoloading perform faster?

like image 845
zed Avatar asked Jun 28 '15 18:06

zed


2 Answers

We had the exact same issue while debugging in New Relic. Finally, we traced it to the filesystem, it turned out we weren't using opcode cache, which can be painful under high load.

Check your opcode caching and try to tweak it's memory settings. That's how we managed to solve it.

like image 95
Небојша Камбер Avatar answered Oct 03 '22 08:10

Небојша Камбер


Note that "optimizing" the autoloading is not necessarily resulting in the best load times in every case. It's a race between getting faster by eliminating file system access versus getting slower by loading more unused stuff into memory.

Why use a PSR-0 or PSR-4 autoload in composer if classmap is actually faster?

like image 23
Sven Avatar answered Oct 03 '22 06:10

Sven