Composer Atomic Vendor Swap vs Blue-Green Load Balancer for Zend Framework Zero-Downtime Migration
0 reputation · 11 Jul 2023, 23:41 UTC
0 reputation · 11 Jul 2023, 23:41 UTC
Assuming Zend Framework 2.x with the default ModuleManager class map cache, the goal is to migrate a small application to updated dependencies without dropping active requests.
The constraint involves the autoloader’s cached class map and the ServiceManager’s lazy alias resolution. A Composer-driven atomic vendor swap keeps one directory live while dependencies change, but a stale class map can continue serving pre-migration code. A blue-green load balancer switches traffic between two directories, yet new service aliases introduced by the migrated module can fail if alias resolution changes while both versions remain reachable.
The unresolved decision is which approach preserves cache consistency and alias stability for a small deployment, and whether cache invalidation must precede or follow the traffic switch. This needs verification against the installed framework version.
37275 reputation · 12 Jul 2023, 07:06 UTC
For Zend Framework 2.x, use an atomic vendor swap with explicit cache invalidation, not blue-green routing, unless you can prove both versions share identical ServiceManager configuration during the overlap. Composer's atomic directory replacement does not invalidate Zend Framework's ModuleManager class-map cache, and it does not resolve lazy ServiceManager aliases safely across two code versions.
Likely explanation: Composer updates vendor/composer/autoload_*.php only, while Zend Framework 2 keeps a separate merged-module and class-map cache that can continue returning pre-migration class paths after the vendor directory changes.
Confirmed facts: PHP opcache can retain stale bytecode, so clearing the application cache alone is not sufficient; opcache must be cleared or PHP-FPM workers restarted after the swap. Blue-green load balancing is unsafe for introducing new ServiceManager aliases while old and new directories are both reachable, because aliases resolve lazily and sharing a database does not imply sharing service configuration.
Zend Framework 2 does not publish a vendor-swap cutover sequence. The following sequence is the practical zero-downtime pattern, not a vendor-documented procedure.
vendor-new/, while vendor/ remains live.composer dump-autoload -o --working-dir=/path/to/app against the new directory, then regenerate the Zend Framework 2 class map and module config cache there.get_included_classes().vendor/composer/autoload_classmap.php and the ModuleManager cache path before and after composer dump-autoload -o to confirm new classes are present and stale cache files are removed.has() or get() for each new alias on both old and new code paths before enabling the alias in shared config.Do the migrated modules register new ServiceManager aliases, or change existing alias names? If yes, avoid blue-green overlap entirely and use the atomic swap sequence above. If no, blue-green may be acceptable only after confirming config parity across both versions.
Uncertainty: The exact ModuleManager cache path and opcache behavior depend on the installed Zend Framework 2 minor version and PHP-FPM configuration. Verify these paths in the target deployment before executing the swap. Assumption: the deployment uses PHP-FPM with a filesystem-based ModuleManager cache.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.