lisachenko / z-engine

:zap: PHP Engine Direct API
MIT License
448 stars 22 forks source link

[Feature] Concept of userland PHP extensions provided as PHP libraries #38

Closed lisachenko closed 4 years ago

lisachenko commented 4 years ago

I have learned a lot about PHP native C extensions and it looks possible to implement a mechanism that will provide an API for development of extensions for userland developers. Every extension is registered in the global registry, called module_registry. It is a simple hash table that contains key-value pairs of pointers to the zend_module_entry entry. And there is main API method zend_register_module_ex which can be used to register new module. So, it should be doable at least...

What is interesting is that combining FFI with userland modules can give a way to survive request boundaries and avoid troubles with memory leaks in FFI itself, because extension can be persistent and PHP will keep it between requests.

In practice this means that it will be possible to carry data or even objects between requests.

enumag commented 4 years ago

@prolic This might be interesting for us I think.

lisachenko commented 4 years ago

@enumag I have already succeeded with userland implementation of modules and can preserv custom structure (CData) between requests without serialization (not PHP objects, as it is so tricky and even can be impossible at all)

Could I ask you about your purpose? What do your expect from user extensions?