Skip to content

Commit

Permalink
Tell couchbase to reattach threads if needed, before shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
srjlewis committed Jul 29, 2024
1 parent ac224cc commit 9e5cc17
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions lib/Phpfastcache/Extensions/Drivers/Couchbasev4/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ public function __construct(ConfigurationOption $config, string $instanceId, Eve
$this->__parentConstruct($config, $instanceId, $em);
}

public function __destruct()
{
static::handleNotifyFork();
}


/**
* @return bool
Expand Down Expand Up @@ -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);
}

Expand All @@ -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;
}
}

Expand All @@ -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;
}
Expand Down

0 comments on commit 9e5cc17

Please sign in to comment.