Skip to content

Commit ae71d1f

Browse files
authored
fix: fiber observers by FFI are not safe on ZTS (#1090)
They aren't _truly_ safe on NTS builds either, as the functions used are only expected to be set at certain times of the lifecycle, but in practice it's safe enough on NTS. However, for ZTS, these APIs are not safe to call at runtime at all.
1 parent 69ba6a9 commit ae71d1f

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ It is recommended to use a `try-finally` statement after `::activate()` to ensur
3535

3636
### Fiber support
3737

38-
Requires `PHP >= 8.1`, `ext-ffi` and setting the environment variable `OTEL_PHP_FIBERS_ENABLED` to a truthy value. Additionally `vendor/autoload.php` has to be preloaded for non-CLI SAPIs if [`ffi.enable`](https://www.php.net/manual/en/ffi.configuration.php#ini.ffi.enable) is set to `preload`.
38+
Requires `PHP >= 8.1`, an NTS build, `ext-ffi`, and setting the environment variable `OTEL_PHP_FIBERS_ENABLED` to a truthy value. Additionally `vendor/autoload.php` has to be preloaded for non-CLI SAPIs if [`ffi.enable`](https://www.php.net/manual/en/ffi.configuration.php#ini.ffi.enable) is set to `preload`.
3939

4040
### Event loops
4141

ZendObserverFiber.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use function filter_var;
1616
use function is_string;
1717
use const PHP_VERSION_ID;
18+
use const PHP_ZTS;
1819
use function sprintf;
1920
use function trigger_error;
2021

@@ -39,8 +40,8 @@ public static function init(): bool
3940
return true;
4041
}
4142

42-
if (PHP_VERSION_ID < 80100 || !extension_loaded('ffi')) {
43-
trigger_error('Context: Fiber context switching not supported, requires PHP >= 8.1 and the FFI extension');
43+
if (PHP_ZTS || PHP_VERSION_ID < 80100 || !extension_loaded('ffi')) {
44+
trigger_error('Context: Fiber context switching not supported, requires PHP >= 8.1, an NTS build, and the FFI extension');
4445

4546
return false;
4647
}

0 commit comments

Comments
 (0)