Bearsampp 2026.7.11
Loading...
Searching...
No Matches
FiberModuleLoader Class Reference

Static Public Member Functions

static getFiber (string $module)
static getLoadedModules ()
static init ()
static isAvailable ()
static isLoaded (string $module)
static isLoading (string $module)
static loadInFiber (string $module, callable $loader, int $timeout=5000)
static waitAll (int $timeout=5000)
static waitForModule (string $module, int $timeout=5000)

Static Private Attributes

static $enabled = false
static $fibers = []

Detailed Description

Class FiberModuleLoader

Manages true asynchronous module loading using PHP 8.1+ Fibers. Fibers provide lightweight pseudo-threading without race conditions.

Works with PHP 8.1+. Falls back gracefully if Fibers unavailable.

Definition at line 17 of file class.fibermoduleloader.php.

Member Function Documentation

◆ getFiber()

getFiber ( string $module)
static

Get fiber for a module (advanced usage)

Parameters
string$moduleModule name
Returns
FiberModule|null The fiber module or null

Definition at line 148 of file class.fibermoduleloader.php.

148 : ?FiberModule
149 {
150 return self::$fibers[$module] ?? null;
151 }

◆ getLoadedModules()

getLoadedModules ( )
static

Get all loaded modules

Returns
array Module names

Definition at line 168 of file class.fibermoduleloader.php.

168 : array
169 {
170 return array_keys(self::$fibers);
171 }

◆ init()

init ( )
static

Initialize Fiber module loader Checks if Fibers are available in this PHP version

Returns
bool True if Fibers available

Definition at line 28 of file class.fibermoduleloader.php.

28 : bool
29 {
30 self::$enabled = PHP_VERSION_ID >= 80100;
31
32 if (!self::$enabled) {
33 Log::warning('FiberModuleLoader unavailable (requires PHP 8.1+, using fallback async)');
34 }
35
36 return self::$enabled;
37 }
static warning($data, $file=null)

References Log\warning().

Referenced by Root\register().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isAvailable()

isAvailable ( )
static

Check if Fibers are available

Returns
bool True if PHP 8.1+ with Fibers

Definition at line 158 of file class.fibermoduleloader.php.

158 : bool
159 {
160 return self::$enabled;
161 }

Referenced by Root\ensureModuleLoaded().

Here is the caller graph for this function:

◆ isLoaded()

isLoaded ( string $module)
static

Check if a module is loaded

Parameters
string$moduleModule name
Returns
bool True if module finished loading

Definition at line 118 of file class.fibermoduleloader.php.

118 : bool
119 {
120 if (!isset(self::$fibers[$module])) {
121 return true; // Not in fiber system
122 }
123
124 return self::$fibers[$module]->isReady();
125 }

◆ isLoading()

isLoading ( string $module)
static

Check if a module is currently loading

Parameters
string$moduleModule name
Returns
bool True if still loading

Definition at line 133 of file class.fibermoduleloader.php.

133 : bool
134 {
135 if (!isset(self::$fibers[$module])) {
136 return false;
137 }
138
139 return !self::$fibers[$module]->isReady();
140 }

◆ loadInFiber()

loadInFiber ( string $module,
callable $loader,
int $timeout = 5000 )
static

Load module in a Fiber (true concurrent) Returns immediately; module loads in background

Parameters
string$moduleModule name
callable$loaderFunction that loads the module
int$timeoutMaximum wait time if accessed before ready (ms)
Returns
bool True if fiber started, false if Fibers unavailable

Definition at line 48 of file class.fibermoduleloader.php.

52 : bool {
53 if (!self::$enabled) {
54 // Fallback: load synchronously
55 call_user_func($loader);
56 return false;
57 }
58
59 // Create fiber for concurrent execution
60 $fiberModule = new FiberModule($module, $loader, $timeout);
61 self::$fibers[$module] = $fiberModule;
62
63 return true;
64 }

References $enabled, and if.

Referenced by Root\loadAppsFiber(), Root\loadHomepageFiber(), Root\loadRegistryFiber(), and Root\loadToolsFiber().

Here is the caller graph for this function:

◆ waitAll()

waitAll ( int $timeout = 5000)
static

Wait for all fibers to complete Useful for synchronization before proceeding

Parameters
int$timeoutMaximum total wait time (ms)
Returns
bool True if all loaded, false if timeout

Definition at line 90 of file class.fibermoduleloader.php.

90 : bool
91 {
92 if (!self::$enabled || empty(self::$fibers)) {
93 return true;
94 }
95
96 $start = microtime(true);
97 $maxWait = $timeout / 1000;
98
99 foreach (self::$fibers as $module => $fiber) {
100 $elapsed = microtime(true) - $start;
101 $remaining = max(100, ($maxWait - $elapsed) * 1000);
102
103 if (!$fiber->wait((int)$remaining)) {
104 Log::warning('Timeout waiting for module: ' . $module);
105 return false;
106 }
107 }
108
109 return true;
110 }

References Log\warning().

Here is the call graph for this function:

◆ waitForModule()

waitForModule ( string $module,
int $timeout = 5000 )
static

Wait for a specific module to finish loading Blocks until module is ready or timeout expires

Parameters
string$moduleModule name
int$timeoutMaximum wait time (ms)
Returns
bool True if module loaded, false if timeout

Definition at line 74 of file class.fibermoduleloader.php.

74 : bool
75 {
76 if (!isset(self::$fibers[$module])) {
77 return true; // Not loaded in fiber, must be ready
78 }
79
80 return self::$fibers[$module]->wait($timeout);
81 }

Referenced by Root\ensureModuleLoaded().

Here is the caller graph for this function:

Field Documentation

◆ $enabled

$enabled = false
staticprivate

Definition at line 20 of file class.fibermoduleloader.php.

Referenced by loadInFiber().

◆ $fibers

$fibers = []
staticprivate

Definition at line 19 of file class.fibermoduleloader.php.


The documentation for this class was generated from the following file: