With a minimal ZF2 skeleton setup completed it is interesting to see what Xdebug makes of it. It is difficult to compare applications by loading time because loading times depend on the hardware used. A better measure is the amount of function calls made: the number is 7711 and by excluding the library functions the number is 3928. On a consumer Windows PC this can translate into 800 ms loading time.

Is this a lot? Considering that all the application does is printing “Hello World” , a single echo() statement could suffice. Is there anything that can be done about this number? The blogs agree on two measures that can be taken.

One optimisation method is explicitly setting templates in the view model of an action in a controller:

public function indexAction()

        // return new ViewModel;
        $viewModel = new ViewModel;
        return $viewModel;

Xdebug agrees: the new number of function calls is 7627.

Activating Zend\Loader\ClassMapAutoloader is another sensible thing to do, it makes autoloading module content a lot faster.

 public function getAutoloaderConfig()
        return array(
            'Zend\Loader\ClassMapAutoloader' => array(
                __DIR__ . '/autoload_classmap.php',
            'Zend\Loader\StandardAutoloader' => array(
                'namespaces' => array(
                    __NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,

This class map can be generated by bin/classmap_generator.php on the command line (run ../../vendor/bin/classmap_generator.php in the application folder). In the current module (Application) the number of entries is just two but in any serious module the gains in loading time are obvious (Note added: in the same way a template_map.php can be added).

On the other hand, in terms of function calls in the current application the new number of 7770 is a disappointment, the value is going up rather than down. With multiple modules, caching of class maps becomes relevant, in the application config the setting module_map_cache_enabled can be set to true. The same config the setting check_dependencies can be set to false. it shaves 30 function calls of the total list and these kind of checks can better be handled by external testing.