PHP loads classes into memory and never frees them as far as I am aware. This can be problematic when using attributes.
I am wondering whether fibers could be used. How independent is a fiber? Ultimately the question is this: if a PHP fiber loads a class, is that going to be autoloaded for the rest of the PHP code or is it a separate memory space?
Code loaded during Fiber execution is available afterwards. Running the following code in Drupal bootstrapped environment:
var_dump(class_exists('\Drupal\Core\Action\Plugin\Action\DeleteAction', FALSE));
$fiber = new Fiber(function() : void {
var_dump(class_exists('\Drupal\Core\Action\Plugin\Action\DeleteAction', TRUE));
});
$fiber->start();
var_dump(class_exists('\Drupal\Core\Action\Plugin\Action\DeleteAction', FALSE));
produces the following output:
bool(false)
bool(true)
bool(true)
Fibers share the same memory space. Each fiber just has its own call stack. If you load a class in a fiber, it's loaded into the process heap, not in the fibers stack allocated memory.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With