Skip to content

Commit fd8f2fe

Browse files
committed
Posix & Pcntl are now optionnal but can be enabled with doPosixCheck config.
1 parent cfbf742 commit fd8f2fe

File tree

5 files changed

+60
-26
lines changed

5 files changed

+60
-26
lines changed

README.md

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,4 @@
1-
## Support & Security
2-
3-
Support for this extension must be posted to the main [Phpfastcache repository](https://github.com/PHPSocialNetwork/phpfastcache/issues).
4-
5-
## Composer installation:
6-
7-
```php
8-
composer install phpfastcache/couchbasev4-extension
9-
```
10-
11-
This extension requires:
12-
13-
- The PHP `Couchbase` extension 4.x at least
14-
- The composer `Couchbase/Couchbase` library 4.x at least
15-
- The PHP `Posix` to fix a known bug [PCBC-886](https://issues.couchbase.com/projects/PCBC/issues/PCBC-886)
16-
17-
18-
## Contributing
1+
## Contributing [![PHP Tests](https://github.com/PHPSocialNetwork/couchbasev4-extension/actions/workflows/php.yml/badge.svg)](https://github.com/PHPSocialNetwork/couchbasev4-extension/actions/workflows/php.yml)
192
Merge requests are welcome but will require the tests plus the quality tools to pass:
203

214
_(Commands must be run from the repository root)_
@@ -37,3 +20,32 @@ _(Commands must be run from the repository root)_
3720
```bash
3821
./vendor/bin/phpstan analyse lib/ -l 6 -c phpstan.neon 2>&1
3922
```
23+
24+
## Support & Security
25+
26+
Support for this extension must be posted to the main [Phpfastcache repository](https://github.com/PHPSocialNetwork/phpfastcache/issues).
27+
28+
## Composer installation:
29+
30+
```php
31+
composer install phpfastcache/couchbasev4-extension
32+
```
33+
34+
#### ⚠️ This extension requires:
35+
36+
1️⃣ The PHP `Couchbase` extension 4.x at least
37+
38+
2️⃣ The composer `Couchbase/Couchbase` library 4.x at least
39+
40+
#### ⚠️ This extension optionally requires:
41+
1️⃣ The PHP `Posix` to fix a known Couchbase Extension bug [PCBC-886](https://issues.couchbase.com/projects/PCBC/issues/PCBC-886).
42+
Once this bug has been fixed the dependency suggestion will be removed.
43+
If your application do manipulate processes with `Posix` extension, and you want the fix to be enabled, set up the config like this:
44+
```php
45+
$config = (new CouchbaseConfig())->setDoPosixCheck(true);
46+
```
47+
48+
2️⃣ Also the PHP `Pcntl` if you plan to contribute to this project and run the tests before pushing your Merge Request.
49+
50+
51+

composer.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,19 @@
2424
"php": ">=8.0",
2525
"phpfastcache/phpfastcache": "^9.2",
2626
"couchbase/couchbase": "^4.0",
27-
"ext-posix": "*",
2827
"ext-couchbase": "^4.0"
2928
},
29+
"suggest": {
30+
"ext-posix": "*",
31+
"ext-pcntl": "*"
32+
},
3033
"require-dev": {
3134
"webmozart/assert": "^1.11",
32-
"ext-pcntl": "*",
3335
"phpmd/phpmd": "@stable",
3436
"squizlabs/php_codesniffer": "@stable",
3537
"phpstan/phpstan": "^1.5",
3638
"jetbrains/phpstorm-stubs": "dev-master"
3739
},
38-
"suggest": {},
3940
"autoload": {
4041
"psr-4": {
4142
"Phpfastcache\\Extensions\\": "lib/Phpfastcache/Extensions"

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
use Couchbase\ClusterOptions;
2121
use Phpfastcache\Config\ConfigurationOption;
22+
use Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException;
2223
use Phpfastcache\Exceptions\PhpfastcacheLogicException;
2324

2425
class Config extends ConfigurationOption
@@ -38,6 +39,7 @@ class Config extends ConfigurationOption
3839
protected bool $secure = false;
3940
protected bool $allowFlush = true;
4041
protected bool $flushFailSilently = false;
42+
protected bool $doPosixCheck = false;
4143

4244
protected ?ClusterOptions $clusterOptions = null;
4345

@@ -222,4 +224,18 @@ public function getClusterOptions(): ClusterOptions
222224
}
223225
return $this->clusterOptions;
224226
}
227+
228+
public function isDoPosixCheck(): bool
229+
{
230+
return $this->doPosixCheck;
231+
}
232+
233+
public function setDoPosixCheck(bool $doPosixCheck): static
234+
{
235+
if ($doPosixCheck && !extension_loaded('posix')) {
236+
throw new PhpfastcacheInvalidArgumentException('Posix extension is required to enable the doPosixCheck config entry.');
237+
}
238+
239+
return $this->setProperty('doPosixCheck', $doPosixCheck);
240+
}
225241
}

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,12 @@ public function __construct(ConfigurationOption $config, string $instanceId, Eve
6969
*/
7070
public function driverCheck(): bool
7171
{
72-
return extension_loaded('couchbase') && extension_loaded('posix');
72+
return extension_loaded('couchbase') && (!$this->getConfig()->isDoPosixCheck() || extension_loaded('posix'));
7373
}
7474

7575
public function getHelp(): string
7676
{
77-
return 'Couchbasev4 requires the `php-couchbase` extension 4.x and the `php-posix` extension';
77+
return 'Couchbasev4 requires the `php-couchbase` extension 4.x and optionally the `php-posix` extension if you enabled the config "doPosixCheck".';
7878
}
7979

8080
/**
@@ -92,7 +92,9 @@ protected function driverConnect(): bool
9292
throw new PhpfastcacheDriverCheckException("You are using Couchbase extension $extVersion, You need to use a Couchbase V4 extension");
9393
}
9494

95-
$this->currentParentPID = posix_getppid();
95+
if ($this->getConfig()->isDoPosixCheck() && extension_loaded('posix')) {
96+
$this->currentParentPID = posix_getppid();
97+
}
9698

9799
$schema = $this->getConfig()->getSecure() ? 'couchbases' : 'couchbase';
98100
$servers = $this->getConfig()->getServers();
@@ -118,8 +120,10 @@ protected function driverConnect(): bool
118120
*/
119121
protected function checkCurrentParentPID(): void
120122
{
121-
if ($this->currentParentPID !== posix_getppid()) {
122-
$this->driverConnect();
123+
if ($this->getConfig()->isDoPosixCheck() && extension_loaded('posix')) {
124+
if ($this->currentParentPID !== posix_getppid()) {
125+
$this->driverConnect();
126+
}
123127
}
124128
}
125129

tests/Couchbasev4.test.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
}
2727

2828
$config = (new CouchbaseConfig(include $configFileName))
29+
->setDoPosixCheck(true)
2930
->setUseStaticItemCaching(false);
3031

3132
$cacheInstance = CacheManager::getInstance('Couchbasev4', $config);

0 commit comments

Comments
 (0)