Bearsampp 2026.9.23
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 159 of file class.fibermoduleloader.php.

159 : ?FiberModule
160 {
161 return self::$fibers[$module] ?? null;
162 }

◆ getLoadedModules()

getLoadedModules ( )
static

Get all loaded modules

Returns
array Module names

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

179 : array
180 {
181 return array_keys(self::$fibers);
182 }

◆ 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 31 of file class.fibermoduleloader.php.

31 : bool
32 {
33 self::$enabled = PHP_VERSION_ID >= 80100;
34
35 if (!self::$enabled) {
36 Log::warning('FiberModuleLoader unavailable (requires PHP 8.1+, using fallback async)');
37 }
38
39 return self::$enabled;
40 }
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 169 of file class.fibermoduleloader.php.

169 : bool
170 {
171 return self::$enabled;
172 }

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 127 of file class.fibermoduleloader.php.

127 : bool
128 {
129 if (!isset(self::$fibers[$module])) {
130 return true; // Not in fiber system
131 }
132
133 return self::$fibers[$module]->isReady();
134 }

◆ 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 143 of file class.fibermoduleloader.php.

143 : bool
144 {
145 if (!isset(self::$fibers[$module])) {
146 return false;
147 }
148
149 return !self::$fibers[$module]->isReady();
150 }

◆ 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 52 of file class.fibermoduleloader.php.

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

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 97 of file class.fibermoduleloader.php.

97 : bool
98 {
99 if (!self::$enabled || empty(self::$fibers)) {
100 return true;
101 }
102
103 $start = microtime(true);
104 $maxWait = $timeout / 1000;
105
106 foreach (self::$fibers as $module => $fiber) {
107 $elapsed = microtime(true) - $start;
108 $remaining = max(100, ($maxWait - $elapsed) * 1000);
109
110 if (!$fiber->wait((int)$remaining)) {
111 Log::warning('Timeout waiting for module: ' . $module);
112
113 return false;
114 }
115 }
116
117 return true;
118 }

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 80 of file class.fibermoduleloader.php.

80 : bool
81 {
82 if (!isset(self::$fibers[$module])) {
83 return true; // Not loaded in fiber, must be ready
84 }
85
86 return self::$fibers[$module]->wait($timeout);
87 }

Referenced by Root\ensureModuleLoaded().

Here is the caller graph for this function:

Field Documentation

◆ $enabled

$enabled = false
staticprivate

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

Referenced by loadInFiber().

◆ $fibers

$fibers = []
staticprivate

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


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