使用 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();
所有的东西都在那个 $loader 上完成,比如 registerNamespaces、registerPrefixes 和所有外部依赖项都被加载到$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();
我做对了吗?显然不是,因为我得到的只是浏览器中一个完全空白的页面,甚至没有写日志以防万一他们能给我一些线索。
先感谢您。