"Unable to resolve service" in production only after enabling laminas config cache
0 reputation · 08 Jun 2024, 15:14 UTC
0 reputation · 08 Jun 2024, 15:14 UTC
Our Laminas MVC application runs cleanly on developer machines, but in production the ServiceManager throws an exception of the form Unable to resolve service \"X\" to a factory for a service whose factory is defined in a module that has been registered in modules.config.php for weeks.
The relevant difference between environments is module_listener_options in application.config.php: production has config_cache_enabled (and the module map cache) turned on, writing the merged configuration into data/cache, while local development does not. We also use the conventional config/autoload/{,*.}{global,local}.php glob, and *.local.php files are excluded from deployment.
What we cannot settle is the intended ownership of the merged-config cache lifecycle. The framework appears to make no decision about when the cached configuration becomes invalid, so every deploy strategy seems to be a convention we must invent ourselves: wipe data/cache on each release, disable the cache entirely, or key the cache file to the release identifier.
Assuming a current laminas-mvc / laminas-modulemanager version pinned in composer.json:
Unable to resolve service error, or should we suspect the missing *.local.php overrides first?data/cache the intended practice?A thoughtful contribution can make all the difference. Be the first to share one.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.