1

Symfony 2.0 を使用して、XCache と連携させようとしています。

XCache が正しくインストールされている。

公式の Symfony ドキュメントに関しては、この XcacheClassLoader.php を作成する必要があります。同じドキュメントに関して、次のようなアドバイスが得られます。

 /**
 * XcacheClassLoader implements a wrapping autoloader cached in Xcache for PHP 5.3.
 *
 * It expects an object implementing a findFile method to find the file. This
 * allows using it as a wrapper around the other loaders of the component (the
 * ClassLoader and the UniversalClassLoader for instance) but also around any
 * other autoloader following this convention (the Composer one for instance)
 *
 *     $loader = new ClassLoader();
 *
 *     // register classes with namespaces
 *     $loader->add('Symfony\Component', __DIR__.'/component');
 *     $loader->add('Symfony',           __DIR__.'/framework');
 *
 *     $cachedLoader = new XcacheClassLoader('my_prefix', $loader);
 *
 *     // activate the cached autoloader
 *     $cachedLoader->register();
 *
 *     // eventually deactivate the non-cached loader if it was registered previously
 *     // to be sure to use the cached one.
 *     $loader->unregister();
 *
 * @author Fabien Potencier <fabien@symfony.com>
 * @author Kris Wallsmith <kris@symfony.com>
 * @author Kim Hemsø Rasmussen <kimhemsoe@gmail.com>
 *
 * @api
 */

私が正しく理解していれば、autoload.php にそのコードが含まれているはずです。これは私が autoload.php でやっていることです:

通常のローダーは次のように宣言されています。

$loader = new UniversalClassLoader();

registerNamespaces、registerPrefixes などのすべての処理がその $loader に対して行われ、すべての外部依存関係が にロードされます$loader

$loader
->registerNamespaces(
    array(
        'Symfony' => array(__DIR__ . '/../vendor/symfony/src',
                __DIR__ . '/../vendor/bundles'),
        'Sensio' => __DIR__ . '/../vendor/bundles',
        'JMS' => __DIR__ . '/../vendor/bundles',
        'Doctrine\\Common' => __DIR__. '/../vendor/doctrine-common/lib',
        'Doctrine\\DBAL' => __DIR__
etc...

すべての「通常の」ものが $loader に対して作成されたら、ドキュメントで述べたように、$cachedLoader を宣言します。

 // register classes with namespaces
 $loader->add('Symfony\Component', __DIR__.'/component');
 $loader->add('Symfony',           __DIR__.'/framework');

 $cachedLoader = new XcacheClassLoader('my_prefix', $loader);

 // activate the cached autoloader
 $cachedLoader->register();

 // eventually deactivate the non-cached loader if it was registered previously
 // to be sure to use the cached one.
 $loader->unregister();

私はそれを正しく理解していますか?明らかにそうではありません。ブラウザに表示されるのは完全に空白のページだけであり、何らかの手がかりが得られる場合に備えてログも書き込まれていないからです。

前もって感謝します。

4

2 に答える 2

1

まだ 2.2 でない場合は、可能であれば 2.2 にアップグレードすることをお勧めします。2.0 は現在、メンテナンス サイクルが終了しています。

しかし、私たちは両方の経験を持っているので、symfony 2.0 には XcacheClassLoader が含まれていないので、それを自分で記述して app/autoload.php に配置する必要があります (APC ローダーが配置される場所と同じ場所に)。symfony 2.2 では、そうではなくなりました。

次に、xcache が正しく機能していることを確認することをお勧めします。php ファイルを作成して、次のようなテストを行うことをお勧めします。

<?php

$something="test";
xcache_set('key', $something, 0);
if (xcache_get('key') !== $something)
    echo "something's wrong...";
else
    echo "xcache appears to be working";

最後に、私たちが行ったことは、Symfony/web/app.php (XcacheClassLoader 用に変更された) の最新バージョンにあるものとほぼ同じです。(単純な形式で) 次のようになります。

<?php

use Symfony\Component\ClassLoader\XcacheClassLoader;
use Symfony\Component\HttpFoundation\Request;

$loader = require_once __DIR__.'/../app/bootstrap.php.cache';

$loader = new XcacheClassLoader('sf2', $loader);
$loader->register(true);

require_once __DIR__.'/../app/AppKernel.php';
require_once __DIR__.'/../app/AppCache.php';

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

// rest of app.php

以下のこのsymfony2ドキュメントリンクは、物事を説明する必要があります(コンポーザーにオートロードファイルをダンプさせることに関する他のポスターのコメントを含む(URLの「現在」に注意してください):

http://symfony.com/doc/current/book/performance.html

于 2013-04-10T07:16:19.723 に答える