Improve Composer\Autoload\includeFile in Symfony

喜夏-厌秋 提交于 2019-12-10 11:41:58

问题


I have made Blackfire test on my Symfony 2.8 project and it shows that most of the time (more than 50%) is used by 435 calls of Composer\Autoload\includeFile

Any suggestions how to improve it? I am using php composer.phar dump-autoload --optimize after I clear cache for prod.

I use APC for metadata and query cache for doctrine and my app.php file looks like this:

<?php

use Symfony\Component\HttpFoundation\Request;

/**
 * @var Composer\Autoload\ClassLoader
 */
$loader = require __DIR__.'/../app/autoload.php';
include_once __DIR__.'/../app/bootstrap.php.cache';

// Enable APC for autoloading to improve performance.
// You should change the ApcClassLoader first argument to a unique prefix
// in order to prevent cache key conflicts with other applications
// also using APC.
/*
$apcLoader = new Symfony\Component\ClassLoader\ApcClassLoader(sha1(__FILE__), $loader);
$loader->unregister();
$apcLoader->register(true);
*/

$kernel = new AppKernel('prod', false);
$kernel->loadClassCache();
//$kernel = new AppCache($kernel);

// When using the HttpCache, you need to call the method in your front controller instead of relying on the configuration parameter
//Request::enableHttpMethodParameterOverride();
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);

回答1:


This function looks like this:

function includeFile($file)
{
    include $file;
}

So this is not the issue with Composer itself. There's nothing to optimize here. You're just including a lot of files.

Anyway, take a closer look at your app.php.

First, you've wrote I use APC (...), and then pasted code snippet containing this:

// Enable APC for autoloading to improve performance.
// You should change the ApcClassLoader first argument to a unique prefix
// in order to prevent cache key conflicts with other applications
// also using APC.
/*
$apcLoader = new Symfony\Component\ClassLoader\ApcClassLoader(sha1(__FILE__), $loader);
$loader->unregister();
$apcLoader->register(true);
*/

I would suggest to follow this hint and uncomment these a few lines of code.

Also there may be possible optimizations in APC configuration.



来源:https://stackoverflow.com/questions/39478418/improve-composer-autoload-includefile-in-symfony

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!