Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Notify parent and child process at the same time #8

Merged
merged 3 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading