Symfony 如何刷新APC类装入器缓存?

Symfony 如何刷新APC类装入器缓存?,symfony,apc,Symfony,Apc,其中提到了在某些类移动时需要刷新APC缓存,这确实是需要的 但是,我找不到如何清除自动加载器的APC缓存。我尝试使用PHPapc\u clear\u cache()函数,但没有效果 如何清除此APC缓存?正如Mauro APC\u clear\u所述,缓存也可以使用参数清除不同类型的APC缓存: apc_clear_cache(); apc_clear_cache('user'); apc_clear_cache('opcode'); 请看 还有一个添加了Symfony apc:c

其中提到了在某些类移动时需要刷新APC缓存,这确实是需要的

但是,我找不到如何清除自动加载器的APC缓存。我尝试使用PHP
apc\u clear\u cache()
函数,但没有效果


如何清除此APC缓存?

正如Mauro APC\u clear\u所述,缓存也可以使用参数清除不同类型的APC缓存:

  apc_clear_cache();
  apc_clear_cache('user');
  apc_clear_cache('opcode');
请看


还有一个添加了Symfony apc:clear命令。

正如Mauro apc\u clear\u cache所提到的,它还可以使用一个参数来清除不同类型的apc缓存:

  apc_clear_cache();
  apc_clear_cache('user');
  apc_clear_cache('opcode');
请看


还有一个添加了Symfony apc:clear命令的命令。

只需创建一个简单的控制器,如下所示

<?php

namespace Rm\DemoBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use JMS\SecurityExtraBundle\Annotation\Secure;

/**
 * apc cache clear controller
 */
class ApcController extends Controller
{

    /**
     * clear action
     *
     * @Route("/cc", name="rm_demo_apc_cache_clear")
     *
     * @Secure(roles="ROLE_SUPER_ADMIN, ROLE_ADMIN")
     *
     * @param \Symfony\Component\HttpFoundation\Request $request
     */
    public function cacheClearAction(Request $request)
    {

        $message = "";

        if (function_exists('apc_clear_cache') 
                && version_compare(PHP_VERSION, '5.5.0', '>=') 
                && apc_clear_cache()) {

            $message .= ' User Cache: success';

        } elseif (function_exists('apc_clear_cache') 
                && version_compare(PHP_VERSION, '5.5.0', '<') 
                && apc_clear_cache('user')) {

            $message .= ' User Cache: success';

        } else {

            $success = false;
            $message .= ' User Cache: failure';

        }

        if (function_exists('opcache_reset') && opcache_reset()) {

            $message .= ' Opcode Cache: success';

        } elseif (function_exists('apc_clear_cache') 
                && version_compare(PHP_VERSION, '5.5.0', '<') 
                && apc_clear_cache('opcode')) {

            $message .= ' Opcode Cache: success';

        } else {
            $success = false;
            $message .= ' Opcode Cache: failure';
        }

        $this->get('session')->getFlashBag()
                            ->add('success', $message);

        // redirect
        $url = $this->container
                ->get('router')
                ->generate('sonata_admin_dashboard');

        return $this->redirect($url);
    }

}
现在,您可以使用以下url清除apc缓存:

http://yourdomain/apc/cc

注意:@Secure(roles=“ROLE\u SUPER\u ADMIN,ROLE\u ADMIN”)注释,这将保护您的apc缓存url免受未经授权的访问。

只需创建一个简单的控制器apc控制器,如下所示

<?php

namespace Rm\DemoBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use JMS\SecurityExtraBundle\Annotation\Secure;

/**
 * apc cache clear controller
 */
class ApcController extends Controller
{

    /**
     * clear action
     *
     * @Route("/cc", name="rm_demo_apc_cache_clear")
     *
     * @Secure(roles="ROLE_SUPER_ADMIN, ROLE_ADMIN")
     *
     * @param \Symfony\Component\HttpFoundation\Request $request
     */
    public function cacheClearAction(Request $request)
    {

        $message = "";

        if (function_exists('apc_clear_cache') 
                && version_compare(PHP_VERSION, '5.5.0', '>=') 
                && apc_clear_cache()) {

            $message .= ' User Cache: success';

        } elseif (function_exists('apc_clear_cache') 
                && version_compare(PHP_VERSION, '5.5.0', '<') 
                && apc_clear_cache('user')) {

            $message .= ' User Cache: success';

        } else {

            $success = false;
            $message .= ' User Cache: failure';

        }

        if (function_exists('opcache_reset') && opcache_reset()) {

            $message .= ' Opcode Cache: success';

        } elseif (function_exists('apc_clear_cache') 
                && version_compare(PHP_VERSION, '5.5.0', '<') 
                && apc_clear_cache('opcode')) {

            $message .= ' Opcode Cache: success';

        } else {
            $success = false;
            $message .= ' Opcode Cache: failure';
        }

        $this->get('session')->getFlashBag()
                            ->add('success', $message);

        // redirect
        $url = $this->container
                ->get('router')
                ->generate('sonata_admin_dashboard');

        return $this->redirect($url);
    }

}
现在,您可以使用以下url清除apc缓存:

http://yourdomain/apc/cc

注意:@Secure(roles=“ROLE\u SUPER\u ADMIN,ROLE\u ADMIN”)注释,这将保护您的apc缓存url不受未经授权的访问。

apc\u clear\u cache()必须工作正常。您是否已检查您的问题是否与symfony缓存有关?谢谢,我将再次尝试使用
apc\u clear\u cache
,我可能没有使用正确的字符串。我也清除了Symfony缓存(以及所有由Composer生成的自动加载器),但没有成功。您是否已检查您的问题是否与symfony缓存有关?谢谢,我将再次尝试使用
apc\u clear\u cache
,我可能没有使用正确的字符串。我也清除了Symfony缓存(以及所有Composer生成的自动加载器),但没有成功。谢谢,这正是我想要的。有关信息,上述行必须在Symfony2应用程序中执行。在
app.php
中临时添加它们就可以了。谢谢,这正是我想要的。有关信息,上述行必须在Symfony2应用程序中执行。将它们临时添加到
app.php
中就可以了。