Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. ZendObserverFiber.php

class ZendObserverFiber

@internal

Hierarchy

  • class \OpenTelemetry\Context\ZendObserverFiber

Expanded class hierarchy of ZendObserverFiber

File

vendor/open-telemetry/context/ZendObserverFiber.php, line 25

Namespace

OpenTelemetry\Context
View source
final class ZendObserverFiber {
    public static function isEnabled() : bool {
        $enabled = $_SERVER['OTEL_PHP_FIBERS_ENABLED'] ?? false;
        return is_string($enabled) ? filter_var($enabled, FILTER_VALIDATE_BOOLEAN) : (bool) $enabled;
    }
    public static function init() : bool {
        static $fibers;
        if ($fibers) {
            return true;
        }
        if (PHP_ZTS || PHP_VERSION_ID < 80100 || !extension_loaded('ffi')) {
            trigger_error('Context: Fiber context switching not supported, requires PHP >= 8.1, an NTS build, and the FFI extension');
            return false;
        }
        try {
            $fibers = FFI::scope('OTEL_ZEND_OBSERVER_FIBER');
        } catch (FFI\Exception) {
            try {
                $fibers = FFI::load(__DIR__ . '/fiber/zend_observer_fiber.h');
            } catch (FFI\Exception $e) {
                trigger_error(sprintf('Context: Fiber context switching not supported, %s', $e->getMessage()));
                return false;
            }
        }
        $storage = new ContextStorage();
        $fibers->zend_observer_fiber_init_register(static fn(int $initializing) => $storage->fork($initializing));
        
        //@phpstan-ignore-line
        $fibers->zend_observer_fiber_switch_register(static fn(int $from, int $to) => $storage->switch($to));
        
        //@phpstan-ignore-line
        $fibers->zend_observer_fiber_destroy_register(static fn(int $destroying) => $storage->destroy($destroying));
        
        //@phpstan-ignore-line
        Context::setStorage($storage);
        return true;
    }

}

Members

Title Sort descending Modifiers Object type Summary
ZendObserverFiber::init public static function
ZendObserverFiber::isEnabled public static function
RSS feed
Powered by Drupal