在 Symfony 中改进 Composer\Autoload\includeFile
Improve Composer\Autoload\includeFile in Symfony
我对我的 Symfony 2.8 项目进行了 Blackfire 测试,它表明大部分时间(超过 50%)被 Composer\Autoload\includeFile
的 435 次调用使用
有什么改进建议吗?
清除产品缓存后,我正在使用 php composer.phar dump-autoload --optimize
。
我将 APC 用于元数据,将查询缓存用于学说,我的 app.php 文件如下所示:
<?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 本身的问题。这里没有什么可以优化的。您只是包含了很多文件。
无论如何,仔细看看你的app.php
。
首先,您写了 我使用 APC (...),然后粘贴了包含以下内容的代码片段:
// 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);
*/
我建议遵循此提示并取消注释这几行代码。
APC 配置也可能有优化。
我对我的 Symfony 2.8 项目进行了 Blackfire 测试,它表明大部分时间(超过 50%)被 Composer\Autoload\includeFile
的 435 次调用使用有什么改进建议吗?
清除产品缓存后,我正在使用 php composer.phar dump-autoload --optimize
。
我将 APC 用于元数据,将查询缓存用于学说,我的 app.php 文件如下所示:
<?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 本身的问题。这里没有什么可以优化的。您只是包含了很多文件。
无论如何,仔细看看你的app.php
。
首先,您写了 我使用 APC (...),然后粘贴了包含以下内容的代码片段:
// 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);
*/
我建议遵循此提示并取消注释这几行代码。
APC 配置也可能有优化。