【问题标题】:Improve Composer\Autoload\includeFile in Symfony改进 Symfony 中的 Composer\Autoload\includeFile
【发布时间】:2016-09-13 20:23:29
【问题描述】:

我对我的 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);

【问题讨论】:

    标签: php symfony composer-php blackfire


    【解决方案1】:

    这个函数看起来像这样:

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

    所以这不是 Composer 本身的问题。这里没有什么可以优化的。你只是包含了很多文件。

    不管怎样,仔细看看你的app.php

    首先,您已经编写了我使用 APC (...),然后粘贴了包含以下内容的代码 sn-p:

    // 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 配置也可能有优化。

    【讨论】:

    • 好的,因此唯一的解决方案是减少文件,这意味着更少的捆绑包。至于 APC,app.php 文件中有什么奇怪的地方,如果我取消注释这 3 行,我会得到比没有它更糟糕的时间。使用这些未注释的行,每个请求需要多花 100 毫秒。
    猜你喜欢
    • 2015-09-15
    • 1970-01-01
    • 2015-06-05
    • 2018-06-06
    • 2023-01-18
    • 1970-01-01
    • 1970-01-01
    • 2017-07-24
    • 2013-12-14
    相关资源
    最近更新 更多