From f7e8d9c414cf3c97566ac7d491d725ade1e8cda3 Mon Sep 17 00:00:00 2001 From: "steven.lewis" Date: Sat, 6 Jan 2024 22:17:42 +0000 Subject: [PATCH] Making the forking detection setting a bit clearer --- README.md | 4 ++-- .../Extensions/Drivers/Couchbasev4/Config.php | 14 +++++++------- .../Extensions/Drivers/Couchbasev4/Driver.php | 8 ++++---- tests/Couchbasev4.test.php | 4 ++-- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index d667dea..427b11b 100644 --- a/README.md +++ b/README.md @@ -40,9 +40,9 @@ composer install phpfastcache/couchbasev4-extension #### ⚠️ This extension optionally requires: 1️⃣ The PHP `Posix` to fix a known Couchbase Extension bug [PCBC-886](https://issues.couchbase.com/projects/PCBC/issues/PCBC-886). Once this bug has been fixed the dependency suggestion will be removed. -If your application do manipulate processes with `Posix` extension, and you want the fix to be enabled, set up the config like this: +If your application wants to fork the processes using `pcntl_fork()` the `Posix` extension is needed, and you want the fix to be enabled, set up the config like this: ```php -$config = (new CouchbaseConfig())->setDoPosixCheck(true); +$config = (new CouchbaseConfig())->doForkDetection(true); ``` 2️⃣ Also the PHP `Pcntl` if you plan to contribute to this project and run the tests before pushing your Merge Request. diff --git a/lib/Phpfastcache/Extensions/Drivers/Couchbasev4/Config.php b/lib/Phpfastcache/Extensions/Drivers/Couchbasev4/Config.php index 2d4c7c0..ec0e5ca 100644 --- a/lib/Phpfastcache/Extensions/Drivers/Couchbasev4/Config.php +++ b/lib/Phpfastcache/Extensions/Drivers/Couchbasev4/Config.php @@ -39,7 +39,7 @@ class Config extends ConfigurationOption protected bool $secure = false; protected bool $allowFlush = true; protected bool $flushFailSilently = false; - protected bool $doPosixCheck = false; + protected bool $doForkDetection = false; protected ?ClusterOptions $clusterOptions = null; @@ -225,17 +225,17 @@ public function getClusterOptions(): ClusterOptions return $this->clusterOptions; } - public function isDoPosixCheck(): bool + public function isDoForkDetection(): bool { - return $this->doPosixCheck; + return $this->doForkDetection; } - public function setDoPosixCheck(bool $doPosixCheck): static + public function setDoForkDetection(bool $doForkDetection): static { - if ($doPosixCheck && !extension_loaded('posix')) { - throw new PhpfastcacheInvalidArgumentException('Posix extension is required to enable the doPosixCheck config entry.'); + if ($doForkDetection && !extension_loaded('posix')) { + throw new PhpfastcacheInvalidArgumentException('Posix extension is required to enable the doForkDetection config entry.'); } - return $this->setProperty('doPosixCheck', $doPosixCheck); + return $this->setProperty('doForkDetection', $doForkDetection); } } diff --git a/lib/Phpfastcache/Extensions/Drivers/Couchbasev4/Driver.php b/lib/Phpfastcache/Extensions/Drivers/Couchbasev4/Driver.php index 3506a82..380a94e 100644 --- a/lib/Phpfastcache/Extensions/Drivers/Couchbasev4/Driver.php +++ b/lib/Phpfastcache/Extensions/Drivers/Couchbasev4/Driver.php @@ -62,12 +62,12 @@ class Driver implements AggregatablePoolInterface */ public function driverCheck(): bool { - return extension_loaded('couchbase') && (!$this->getConfig()->isDoPosixCheck() || extension_loaded('posix')); + return extension_loaded('couchbase') && (!$this->getConfig()->isDoForkDetection() || extension_loaded('posix')); } public function getHelp(): string { - return 'Couchbasev4 requires the `php-couchbase` extension 4.x and optionally the `php-posix` extension if you enabled the config "doPosixCheck".'; + return 'Couchbasev4 requires the `php-couchbase` extension 4.x and optionally the `php-posix` extension if you enabled the config "doForkDetection".'; } /** @@ -85,7 +85,7 @@ protected function driverConnect(): bool throw new PhpfastcacheDriverCheckException("You are using Couchbase extension $extVersion, You need to use a Couchbase V4 extension"); } - if ($this->getConfig()->isDoPosixCheck() && extension_loaded('posix')) { + if ($this->getConfig()->isDoForkDetection() && extension_loaded('posix')) { $this->currentParentPID = posix_getppid(); } @@ -113,7 +113,7 @@ protected function driverConnect(): bool */ protected function checkCurrentParentPID(): void { - if ($this->getConfig()->isDoPosixCheck() && extension_loaded('posix')) { + if ($this->getConfig()->isDoForkDetection() && extension_loaded('posix')) { if ($this->currentParentPID !== posix_getppid()) { $this->driverConnect(); } diff --git a/tests/Couchbasev4.test.php b/tests/Couchbasev4.test.php index 6893df0..aa5d559 100644 --- a/tests/Couchbasev4.test.php +++ b/tests/Couchbasev4.test.php @@ -31,7 +31,7 @@ $testHelper->printInfoText('Running forking failure process test'); $config = (new CouchbaseConfig(include $configFileName)) - ->setDoPosixCheck(false) + ->setDoForkDetection(false) ->setUseStaticItemCaching(false); $cacheInstance = CacheManager::getInstance('Couchbasev4', $config); @@ -60,7 +60,7 @@ $testHelper->printInfoText('Running forking success process test'); $config = (new CouchbaseConfig(include $configFileName)) - ->setDoPosixCheck(true) + ->setDoForkDetection(true) ->setUseStaticItemCaching(false); $cacheInstance = CacheManager::getInstance('Couchbasev4', $config);