Skip to content

Commit

Permalink
Merge pull request #8 from srjlewis/master
Browse files Browse the repository at this point in the history
Notify parent and child process at the same time
  • Loading branch information
Geolim4 authored Nov 27, 2024
2 parents 65f0c77 + c32b7cf commit 16dca4e
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
strategy:
matrix:
operating-system: [ubuntu-latest]
php-versions: ['8.0', '8.1', '8.2', '8.3']
php-versions: ['8.0', '8.1', '8.2', '8.3', '8.4']
ext-versions: ['couchbase-4.1.6', 'couchbase']
name: PHP ${{ matrix.php-versions }} using ${{ matrix.ext-versions }} quality/tests on ${{ matrix.operating-system }}
env:
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 9.2.3
#### 27 November 2024
- __Driver Core__
- `Couchbasev4` Allow call to `handleNotifyFork()` after process has been forked, this is due
- to a change in the couchbase SDK that needs parent and child to be notified at the same time.


## 9.2.2
#### 29 July 2024
- __Driver Core__
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,16 @@ composer install phpfastcache/couchbasev4-extension

To fork a php process correctly you will need to tell the Couchbase diver to prepare for the fork.

⚠️ __WARNING__ You **must** call the drivers `Phpfastcache\Drivers\Couchbasev4\Driver::prepareToFork()` just before the `pcntl_fork()` call or the child process will lock up.
⚠️ __WARNING__ You **must** call the drivers `Phpfastcache\Drivers\Couchbasev4\Driver::prepareToFork()`
just before the `pcntl_fork()` call or the child process will lock up and then call `handleNotifyFork()` to avoid further
errors.

#### Example
```php
try {
\Phpfastcache\Drivers\Couchbasev4\Driver::prepareToFork();
$pid = pcntl_fork();
\Phpfastcache\Drivers\Couchbasev4\Driver::handleNotifyFork();
if ($pid == -1) {
// There was a problem with forking the process
} else if ($pid) {
Expand Down
6 changes: 5 additions & 1 deletion lib/Phpfastcache/Extensions/Drivers/Couchbasev4/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,12 @@ protected function handleForkedProcess(): void
}
}

protected static function handleNotifyFork(): void
public static function handleNotifyFork(): void
{
if (!isset(static::$posixLoaded) && !isset(static::$extVersion)) {
return;
}

if (static::$prepareToForkPPID && \version_compare(static::$extVersion, '4.2.1', '>=')) {
if (static::$prepareToForkPPID === \posix_getpid()) {
Cluster::notifyFork(ForkEvent::PARENT);
Expand Down
1 change: 1 addition & 0 deletions tests/Couchbasev4.test.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
try {
\Phpfastcache\Extensions\Drivers\Couchbasev4\Driver::prepareToFork();
$pid = \pcntl_fork();
\Phpfastcache\Extensions\Drivers\Couchbasev4\Driver::handleNotifyFork();
if ($pid == -1) {
$testHelper->assertFail('Unable to fork');
} else if ($pid) {
Expand Down

0 comments on commit 16dca4e

Please sign in to comment.