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

Breadcrumb

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

function ZendObserverFiber::init

1 call to ZendObserverFiber::init()
initialize_fiber_handler.php in vendor/open-telemetry/context/fiber/initialize_fiber_handler.php

File

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

Class

ZendObserverFiber
@internal

Namespace

OpenTelemetry\Context

Code

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;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal