Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/symfony/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Symfony2和XCache。有人让它工作了吗?_Php_Symfony_Xcache - Fatal编程技术网

Php Symfony2和XCache。有人让它工作了吗?

Php Symfony2和XCache。有人让它工作了吗?,php,symfony,xcache,Php,Symfony,Xcache,使用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

使用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
 */
所有的东西都被加载到$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();
我说得对吗?显然不是,因为我得到的只是浏览器中的一个完全空白的页面,甚至没有写日志,以防它们能给我一些线索


提前谢谢。

我没有使用XCache,但我可以向您推荐一种提高类加载性能的替代方法,就我记忆所及,这是最好的方法

检查官方文件的一节

参考文献:


如果您还没有达到2.2,我建议您尽可能升级到2.2。2.0现在已处于其维护周期的末尾

但是,因为我们在这两方面都有经验——对于symfony 2.0,没有包含XcacheClassLoader,所以您必须自己编写它,然后将它放在app/autoload.php中(与APC loader放在同一位置)。对于symfony 2.2来说,情况不再如此

接下来,我建议您确保xcache工作正常-您可能希望创建一个php文件并执行如下测试:


 // 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();
By default, the Symfony2 standard edition uses Composer's autoloader in the 
autoload.php file. This autoloader is easy to use, as it will automatically find 
any new classes that you've placed in the registered directories.

Unfortunately, this comes at a cost, as the loader iterates over all configured 
namespaces to find a particular file, making file_exists calls until it finally 
finds the file it's looking for.

The simplest solution is to tell Composer to build a "class map" (i.e. a big 
array of the locations of all the classes). This can be done from the command 
line, and might become part of your deploy process:

    php composer.phar dump-autoload --optimize

Internally, this builds the big class map array in 
vendor/composer/autoload_namespaces.php.