{"record":{"id":"a7ea25fcd577f5e0","repo":"doctrine/orm","slug":"cannot-clear-apcu-cache-from-console-it-s-shared","errorCode":null,"errorMessage":"Cannot clear APCu Cache from Console, it's shared in the Webserver memory and not accessible from the CLI.","messagePattern":"Cannot clear APCu Cache from Console, it's shared in the Webserver memory and not accessible from the CLI\\.","errorType":"console","errorClass":"LogicException","httpStatus":null,"severity":"error","filePath":"src/Tools/Console/Command/ClearCache/QueryCommand.php","lineNumber":43,"sourceCode":"        $this->setName('orm:clear-cache:query')\n             ->setDescription('Clear all query cache of the various cache drivers')\n             ->addOption('em', null, InputOption::VALUE_REQUIRED, 'Name of the entity manager to operate on')\n             ->setHelp('The <info>%command.name%</info> command is meant to clear the query cache of associated Entity Manager.');\n    }\n\n    protected function execute(InputInterface $input, OutputInterface $output): int\n    {\n        $ui = (new SymfonyStyle($input, $output))->getErrorStyle();\n\n        $em    = $this->getEntityManager($input);\n        $cache = $em->getConfiguration()->getQueryCache();\n\n        if (! $cache) {\n            throw new InvalidArgumentException('No Query cache driver is configured on given EntityManager.');\n        }\n\n        if ($cache instanceof ApcuAdapter) {\n            throw new LogicException('Cannot clear APCu Cache from Console, it\\'s shared in the Webserver memory and not accessible from the CLI.');\n        }\n\n        $ui->comment('Clearing <info>all</info> Query cache entries');\n\n        $message = $cache->clear() ? 'Successfully deleted cache entries.' : 'No cache entries were deleted.';\n\n        $ui->success($message);\n\n        return 0;\n    }\n}\n","sourceCodeStart":25,"sourceCodeEnd":55,"githubUrl":"https://github.com/doctrine/orm/blob/d9b9ff73016bf598ae07515f97289ce8074e97a5/src/Tools/Console/Command/ClearCache/QueryCommand.php#L25-L55","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"# before\n$ php bin/console doctrine:orm:clear-cache:query\n# LogicException: Cannot clear APCu Cache from Console...\n\n# after: clear from the web process during deploy\n$ curl -fsS https://app.example.com/internal/apcu-clear\n# (endpoint backed by apcu_clear_cache(), protected by auth/firewall)","handlingStrategy":"validation","validationCode":"use Symfony\\Component\\Cache\\Adapter\\ApcuAdapter;\n\n$cache = $em->getConfiguration()->getQueryCache();\nif ($cache instanceof ApcuAdapter) {\n    // CLI clear is a no-op for fpm's APCu: trigger the web-context clear,\n    // e.g. an authenticated HTTP endpoint that calls apcu_clear_cache()\n    return $http->post('https://app.example.com/internal/apcu-clear');\n}\n// otherwise safe to run orm:clear-cache:query","typeGuard":null,"tryCatchPattern":"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.","preventionTips":["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."],"tags":["doctrine-orm","console","apcu","cache","php-fpm","deployment"],"backgroundTag":"cache-clear-unsupported-backend","analyzedSha":"d9b9ff73016bf598ae07515f97289ce8074e97a5","analyzedAt":"2026-08-21T06:13:15.863Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}