From 9e5cc176d61ab98f2191e0a68442889d553a5347 Mon Sep 17 00:00:00 2001 From: "steven.lewis" Date: Mon, 29 Jul 2024 13:50:25 +0100 Subject: [PATCH] Tell couchbase to reattach threads if needed, before shutdown --- .../Extensions/Drivers/Couchbasev4/Driver.php | 36 ++++++++++--------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/lib/Phpfastcache/Extensions/Drivers/Couchbasev4/Driver.php b/lib/Phpfastcache/Extensions/Drivers/Couchbasev4/Driver.php index c669ab3..332f016 100644 --- a/lib/Phpfastcache/Extensions/Drivers/Couchbasev4/Driver.php +++ b/lib/Phpfastcache/Extensions/Drivers/Couchbasev4/Driver.php @@ -90,6 +90,11 @@ public function __construct(ConfigurationOption $config, string $instanceId, Eve $this->__parentConstruct($config, $instanceId, $em); } + public function __destruct() + { + static::handleNotifyFork(); + } + /** * @return bool @@ -164,13 +169,7 @@ public static function prepareToFork(): void } if (\version_compare(static::$extVersion, '4.2.1', '>=')) { - if (static::$prepareToForkPPID) { - if (static::$prepareToForkPPID === \posix_getpid()) { - Cluster::notifyFork(ForkEvent::PARENT); - } else { - Cluster::notifyFork(ForkEvent::CHILD); - } - } + static::handleNotifyFork(); Cluster::notifyFork(ForkEvent::PREPARE); } @@ -195,15 +194,20 @@ protected function handleForkedProcess(): void $this->connect(\posix_getppid()); } - if (\version_compare(static::$extVersion, '4.2.1', '>=')) { - if (static::$prepareToForkPPID === \posix_getpid()) { - Cluster::notifyFork(ForkEvent::PARENT); - } else { - Cluster::notifyFork(ForkEvent::CHILD); - } - static::$prepareToForkPPID = 0; - } + static::handleNotifyFork(); + } + } + } + + protected static function handleNotifyFork(): void + { + if (static::$prepareToForkPPID && \version_compare(static::$extVersion, '4.2.1', '>=')) { + if (static::$prepareToForkPPID === \posix_getpid()) { + Cluster::notifyFork(ForkEvent::PARENT); + } else { + Cluster::notifyFork(ForkEvent::CHILD); } + static::$prepareToForkPPID = 0; } } @@ -221,7 +225,7 @@ protected function driverRead(ExtendedCacheItemInterface $item): ?array /** * CouchbaseBucket::get() returns a GetResult interface */ - return $this->decodeDocument((array)$this->getCollection()->get($item->getEncodedKey())->content()); + return $this->decodeDocument((array) $this->getCollection()->get($item->getEncodedKey())->content()); } catch (DocumentNotFoundException) { return null; }