1
votes

I try use the following codes to clear cache by web way, but I got the response message:

// Clearing the cache for the dev environment with debug // true [Symfony\Component\Debug\Exception\ContextErrorException] Warning: ini_set(): A session is active. You cannot change the session modu le's ini settings at this time cache:clear [--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] [--]

My code is as follows:

/**
* @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:my php.ini session.auto_start => Off => Off

2
I try it this way ,It works! $input = new ArrayInput([ 'command' => 'cache:clear', '--env' => 'dev', '--no-warmup' => true ]);X.Sophie
Accept your answer, explaining what was wrong.COil
I read documnet(symfony.com/doc/current/reference/…) # New in version 3.3: Starting from Symfony 3.3, the warm-up part of the cache:clear command is deprecated. You must always pass the --no-warmup option to cache:clear and use cache:warmup instead to warm-up the cache.X.Sophie

2 Answers

1
votes
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);
}
0
votes

This work but for my return error

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.

So i use

exec("pwd;  cd ./../; pwd; php bin/console cache:clear --env=prod",$content);

In Symfony 4 - pwd is /public :)