1

我在我的项目中使用 Doctrine 2.4.6(不是 Symfony)。而且我需要清除缓存元数据,但是当我执行该命令时:

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

我收到了这个错误:

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]

这里有什么问题?我可以通过 PHP 代码编写一些代码太清除缓存吗?

4

1 回答 1

1

您的问题是,即使有该命令,您也无法从命令行清除缓存。为了解决这个问题,我实现了这个脚本(从另一个我现在找不到的 SO 答案复制)

这在你的命令行上: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);
}

在您的网络服务器中:

<?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');
}

希望这可以帮助!

于 2015-02-05T16:14:18.663 回答