我尝试使用以下代码通过Web方式清除缓存,但我收到了响应消息:
//使用debug // true清除dev环境的缓存 [Symfony \ Component \ Debug \ Exception \ ContextErrorException]警告: ini_set():会话处于活动状态。您无法更改会话模式 此时缓存中的lei设置:清除[--no-warmup] [--no-optional-warmers] [-h | --help] [-q | --quiet] [-v | vv | vvv | --verbose] [-V | --version] [--ansi] [ - no-ansi] [-n | --no-interaction] [-e | --env ENV] [--no-debug] [ - ]
我的代码如下:
/**
* @Route("/cache/clear", name="cache_clear")
*/
public function cacheClearAction( )
{
$application = new Application($this->get('kernel'));
$application->setAutoExit(false);//exit after run
$input = new ArrayInput([
'command' => 'cache:clear',
'--env' => 'dev',
]);
$output = new BufferedOutput();
$runCode = $application->run($input, $output);
$content = $output->fetch();
return new Response($content);
}
ps:我的php.ini session.auto_start => Off =>关
答案 0 :(得分:1)
public function cacheClearAction( )
{
$application = new Application($this->get('kernel'));
$application->setAutoExit(false);//exit after run
$input = new ArrayInput([
'command' => 'cache:clear',
'--env' => 'dev',
'--no-warmup' => true
]);
$output = new BufferedOutput();
$runCode = $application->run($input, $output);
$content = $output->fetch();
return new Response($content);
}
答案 1 :(得分:0)
这项工作可是我的返回错误
public function cacheClearAction( )
{
$application = new Application($this->get('kernel'));
$application->setAutoExit(false);//exit after run
$input = new ArrayInput([
'command' => 'cache:clear',
'--env' => 'dev',
'--no-warmup' => true
]);
$output = new BufferedOutput();
$runCode = $application->run($input, $output);
$content = $output->fetch();
return new Response($content);
}
// Clearing the cache for the dev environment with debug // true // Warming up cache... 09:58:05 DEBUG [php] Warning: unlink(/application/var/cache/de_/Container9daLmfA.legacy): No such file or directory [ "exception" => Symfony\Component\Debug\Exception\SilencedErrorContext { +count: 1 -severity: E_WARNING trace: { /application/vendor/symfony/http-kernel/Kernel.php:746 { …} /application/vendor/symfony/http-kernel/Kernel.php:566 { …} } } ] // Removing old cache directory... // Finished [OK] Cache for the "dev" environment (debug=true) was successfully cleared.
所以我用
exec("pwd; cd ./../; pwd; php bin/console cache:clear --env=prod",$content);
在Symfony 4中-pwd为/ public:)