I use ZendFramework2 and Doctrine for launching my project. My CPU shows high usage on httpd
requests. I enabled opcache
for filecaching, and memcache
for Doctrine.
Any idea why it might have a load average being near 5.0? I put die('test1')
inside of onBootstrap
of ZendFramework2 one time, and another time I put die('test')
before.
die('test2')
Zend\Mvc\Application::init(require 'config/application.config.php')->run();
My Apache bench shows that when the framework is loaded without any connection to a database or goes to any controller it's 5x slower. Why is zf2 acting like this and what might be a possible solution to normalize it's behavior?
[question update]
I profiled with Xdebug And Webgrind and found out processes like on bootstrap take high percentage
( Application\Module->onBootstrap)
on bootstrap I have this line of codes
//...
$eventManager->attach(MvcEvent::EVENT_ROUTE, function($e) use ($blacklistForNormalUser, $auth) {
$match = $e->getRouteMatch();
// No route match, this is a 404
if (!$match instanceof RouteMatch) {
return;
}
// Route is whitelisted
$name = $match->getMatchedRouteName();
if (!in_array($name, $blacklistForNormalUser) ) {
return;
}
// User is authenticated
if ($auth->hasIdentity() ) {
return;
}
// Redirect to the user login page, as an example
$router = $e->getRouter();
if(in_array($name, $blacklistForNormalUser)){
$url = $router->assemble(array(), array(
'name' => 'user/login'
));
}
$response = $e->getResponse();
$response->getHeaders()->addHeaderLine('Location', $url);
$response->setStatusCode(302);
return $response;
}, -100);
//...
another high point is
Doctrine\ORM\Mapping\Driver\AnnotationDriver->loadMetadataForClass