在Symfony中改进Composer \ Autoload \ includeFile [英] Improve Composer\Autoload\includeFile in Symfony
问题描述
我已经在Symfony 2.8项目上进行了Blackfire测试,结果表明,大部分时间(超过50%)被435个Composer \ Autoload \ includeFile调用使用
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
任何建议如何改进它?
清除产品缓存后,我正在使用php composer.phar dump-autoload --optimize
.
Any suggestions how to improve it?
I am using php composer.phar dump-autoload --optimize
after I clear cache for prod.
我将APC用于元数据,并将查询缓存用于原则,而我的app.php文件如下所示:
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);
推荐答案
此函数如下:
function includeFile($file)
{
include $file;
}
因此,这不是Composer本身的问题.这里没有什么要优化的.您只是包含了很多文件.
So this is not the issue with Composer itself. There's nothing to optimize here. You're just including a lot of files.
无论如何,请仔细查看您的app.php
.
Anyway, take a closer look at your app.php
.
首先,您编写了我使用APC(...),然后粘贴了包含以下内容的代码段:
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.
此外,APC配置可能还会进行优化.
Also there may be possible optimizations in APC configuration.
这篇关于在Symfony中改进Composer \ Autoload \ includeFile的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!