我在我的项目中使用了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代码编写一些代码太清晰的缓存吗?
答案 0 :(得分: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');
}
希望这有帮助!