doctrine/orm · error · LogicException
Cannot clear APCu Cache from Console, it's shared in the Web
Error message
Cannot clear APCu Cache from Console, it's shared in the Webserver memory and not accessible from the CLI.
What it means
APCu keeps entries in shared memory owned by the process that populated it — for a website that is php-fpm, not the CLI. Clearing an ApcuAdapter from a console command would only empty the CLI process's own APCu segment and leave the web cache untouched, so orm:clear-cache:query throws LogicException when the configured query cache is a Symfony ApcuAdapter, refusing a silently ineffective operation.
Source
Thrown at src/Tools/Console/Command/ClearCache/QueryCommand.php:43
$this->setName('orm:clear-cache:query')
->setDescription('Clear all query cache of the various cache drivers')
->addOption('em', null, InputOption::VALUE_REQUIRED, 'Name of the entity manager to operate on')
->setHelp('The <info>%command.name%</info> command is meant to clear the query cache of associated Entity Manager.');
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$ui = (new SymfonyStyle($input, $output))->getErrorStyle();
$em = $this->getEntityManager($input);
$cache = $em->getConfiguration()->getQueryCache();
if (! $cache) {
throw new InvalidArgumentException('No Query cache driver is configured on given EntityManager.');
}
if ($cache instanceof ApcuAdapter) {
throw new LogicException('Cannot clear APCu Cache from Console, it\'s shared in the Webserver memory and not accessible from the CLI.');
}
$ui->comment('Clearing <info>all</info> Query cache entries');
$message = $cache->clear() ? 'Successfully deleted cache entries.' : 'No cache entries were deleted.';
$ui->success($message);
return 0;
}
}
View on GitHub (pinned to d9b9ff7301)
Solutions
- Clear APCu from the web context: expose an authenticated internal endpoint calling apcu_clear_cache() and request it (e.g. curl) during deploy.
- Switch the query cache to a backend shared across processes (Redis, Memcached, filesystem) so CLI clearing actually works.
- As a blunt fallback, restart php-fpm after deploys so the APCu segment is rebuilt empty.
Example fix
# before $ php bin/console doctrine:orm:clear-cache:query # LogicException: Cannot clear APCu Cache from Console... # after: clear from the web process during deploy $ curl -fsS https://app.example.com/internal/apcu-clear # (endpoint backed by apcu_clear_cache(), protected by auth/firewall)
Defensive patterns
Strategy: validation
Validate before calling
use Symfony\Component\Cache\Adapter\ApcuAdapter;
$cache = $em->getConfiguration()->getQueryCache();
if ($cache instanceof ApcuAdapter) {
// CLI clear is a no-op for fpm's APCu: trigger the web-context clear,
// e.g. an authenticated HTTP endpoint that calls apcu_clear_cache()
return $http->post('https://app.example.com/internal/apcu-clear');
}
// otherwise safe to run orm:clear-cache:query Try / catch
Catch \LogicException around the command call and branch to the web-context clearing mechanism; do not retry from the CLI — the shared-memory segment is simply not reachable.
Prevention
- Do not use APCu for caches that must be cleared from the CLI; use Redis/Memcached/filesystem.
- Provide an authenticated web endpoint for apcu_clear_cache() and call it during deploy.
- Restart php-fpm as a fallback after deployments to drop stale APCu entries.
When it happens
Trigger: Running orm:clear-cache:query with the query cache configured as Symfony\Component\Cache\Adapter\ApcuAdapter (doctrine-bundle cache.adapter.apcu / new ApcuAdapter()) on a setup where the web SAPI (php-fpm, Apache mod_php) owns the populated APCu memory.
Common situations: Symfony prod setups using APCu for speed; deploy pipelines running cache:clear on the CLI while traffic is served by fpm; container images where fpm and CLI share configuration.
Related errors
- No second-level cache is configured on the given EntityManag
- Missing arguments "--owner-class" "--association"
- No second-level cache is configured on the given EntityManag
- Invalid argument "--entity-class"
- No Metadata cache driver is configured on given EntityManage
AI-assisted analysis of doctrine/orm@d9b9ff7301 (2026-08-21).
Data as JSON: /api/errors/a7ea25fcd577f5e0.
Report an issue: GitHub.