phpcachingdoctrine-ormclear-cache

Doctrine 2.4.6 can't clear cache via CentOS console


I'm using Doctrine 2.4.6 in my project (not with Symfony). And I need to clear cache metadata, but when I execute that commands:

cd /home/folder/public_html/includes/doctrine
php vendor/doctrine/orm/bin/doctrine orm:clear-cache:metadata

I got this error:

PHP Warning:  php_uname() has been disabled for security reasons in /home/folder/public_html/includes/doctrine/vendor/symfony/console/Symfony/Component/Console/Output/ConsoleOutput.php on line 111



  [LogicException]                                                                                          
  Cannot clear APC Cache from Console, its shared in the Webserver memory and not accessible from the CLI.  



orm:clear-cache:metadata [--flush]

What wrong here? Can I write some code too clear cache via PHP code?


Solution

  • Your problem is that you cannot clear the cache from the command line even though there's that command. To fix this I implemented this script (copied from another SO answer that I can't find right now)

    This on your command line: clear_cache_cli.php

    $url = 'https://YOURDOMAINENAMEHERE/apc_clear.php'; //use domain name as necessary
    $result = file_get_contents($url);
    $result_json = json_decode($result);
    if (isset($result_json['success']) && $result_json['success'])
    {
      echo 'Cache borrada!';//handle success
      exit(0);
    } else {
       echo 'Error!';
       var_dump($result);//handle failure
       exit(1);
    }
    

    In your web server:

    <?php
    if (in_array(@$_SERVER['REMOTE_ADDR'], array('127.0.0.1', '::1','YOUR_WEB_SERVER_IP','')))
    {
      apc_clear_cache();
      apc_clear_cache('user');
      apc_clear_cache('opcode');
      echo json_encode(array('success' => true));
    }
    else
    {
      die('SUPER TOP SECRET');
    }
    

    Hope this helps!