Skip to content

Commit 9e5cc17

Browse files
committed
Tell couchbase to reattach threads if needed, before shutdown
1 parent ac224cc commit 9e5cc17

File tree

1 file changed

+20
-16
lines changed
  • lib/Phpfastcache/Extensions/Drivers/Couchbasev4

1 file changed

+20
-16
lines changed

lib/Phpfastcache/Extensions/Drivers/Couchbasev4/Driver.php

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@ public function __construct(ConfigurationOption $config, string $instanceId, Eve
9090
$this->__parentConstruct($config, $instanceId, $em);
9191
}
9292

93+
public function __destruct()
94+
{
95+
static::handleNotifyFork();
96+
}
97+
9398

9499
/**
95100
* @return bool
@@ -164,13 +169,7 @@ public static function prepareToFork(): void
164169
}
165170

166171
if (\version_compare(static::$extVersion, '4.2.1', '>=')) {
167-
if (static::$prepareToForkPPID) {
168-
if (static::$prepareToForkPPID === \posix_getpid()) {
169-
Cluster::notifyFork(ForkEvent::PARENT);
170-
} else {
171-
Cluster::notifyFork(ForkEvent::CHILD);
172-
}
173-
}
172+
static::handleNotifyFork();
174173
Cluster::notifyFork(ForkEvent::PREPARE);
175174
}
176175

@@ -195,15 +194,20 @@ protected function handleForkedProcess(): void
195194
$this->connect(\posix_getppid());
196195
}
197196

198-
if (\version_compare(static::$extVersion, '4.2.1', '>=')) {
199-
if (static::$prepareToForkPPID === \posix_getpid()) {
200-
Cluster::notifyFork(ForkEvent::PARENT);
201-
} else {
202-
Cluster::notifyFork(ForkEvent::CHILD);
203-
}
204-
static::$prepareToForkPPID = 0;
205-
}
197+
static::handleNotifyFork();
198+
}
199+
}
200+
}
201+
202+
protected static function handleNotifyFork(): void
203+
{
204+
if (static::$prepareToForkPPID && \version_compare(static::$extVersion, '4.2.1', '>=')) {
205+
if (static::$prepareToForkPPID === \posix_getpid()) {
206+
Cluster::notifyFork(ForkEvent::PARENT);
207+
} else {
208+
Cluster::notifyFork(ForkEvent::CHILD);
206209
}
210+
static::$prepareToForkPPID = 0;
207211
}
208212
}
209213

@@ -221,7 +225,7 @@ protected function driverRead(ExtendedCacheItemInterface $item): ?array
221225
/**
222226
* CouchbaseBucket::get() returns a GetResult interface
223227
*/
224-
return $this->decodeDocument((array)$this->getCollection()->get($item->getEncodedKey())->content());
228+
return $this->decodeDocument((array) $this->getCollection()->get($item->getEncodedKey())->content());
225229
} catch (DocumentNotFoundException) {
226230
return null;
227231
}

0 commit comments

Comments
 (0)