Skip to content

Commit

Permalink
Making the forking detection setting a bit clearer
Browse files Browse the repository at this point in the history
  • Loading branch information
srjlewis committed Jan 6, 2024
1 parent 93af157 commit f7e8d9c
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
14 changes: 7 additions & 7 deletions lib/Phpfastcache/Extensions/Drivers/Couchbasev4/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}
}
8 changes: 4 additions & 4 deletions lib/Phpfastcache/Extensions/Drivers/Couchbasev4/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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".';
}

/**
Expand All @@ -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();
}

Expand Down Expand Up @@ -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();
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Couchbasev4.test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit f7e8d9c

Please sign in to comment.