On Sun, Jan 4, 2015 at 1:36 PM, François Laupretre <franc...@tekwire.net> wrote:
> > De : Benjamin Eberlei [mailto:kont...@beberlei.de] > > I want to open discussion on my RFC to strengthen the ability of > extensions > > to provide functionality to developers in both C **and** PHP code. > > > > For this extensions can add PHP files to a list of "prepend files" that > are > > part of every request execution exactly the same way the INI > > auto_prepend_file functionality works: > > > > https://wiki.php.net/rfc/extension_prepend_files > > > > I propose implementation details in the RFC, but they are completely up > to > > discussion. I am even sure there is probably a better way than what I > > proposed, because I am not familiar with the code. > > Can you please develop the API changes in your RFC ? You're talking about > changes in zend_execute_scripts(), a new zend_execute_script() function > (but the name in the prototype is wrong), then php_execute_scripts()... > Fixed the typo in zend_execute_script. The API of php_execute_scripts doesnt change, only the implementation. > > Where are the file handles coming from ? Does it mean that the files to > prepend will be kept open ? > File handles have existed before in php_execute_scripts, they were passed via the va_list into zend_execute_scripts. > > Do you register paths to prepend, or will the scripts be loaded in memory > during MINIT ? > You register file paths to prepend. > > How will these files be cached by opcode caches (mandatory for such a > feature) ? > Files will be cached, because opcache hooks into zend_compile_file, which is used downstream of zend_execute_scripts. That means the feature would autoamtically use and work with opcache. > > And, finally, how can an extension determine where a given PHP script it > requires has been installed ? It makes sense in php.ini because it is under > control of the final user. But an extension is just a C library, installed > anywhere or bundled in the PHP executable. Would it compute the script > paths from PHP installation paths ? > Files must be either in the PHP include path, or via absolute path, for example by putting them right next to the shared object (.so) files and using the extension_dir path inside the code, see the following for an example (a hacked approach): https://github.com/QafooLabs/php-profiler-extension/blob/master/qafooprofiler.c#L744 > Actually, I don't see how it would work with PHP scripts which would > remain separate from the extension code. What I would imagine for such a > feature, would be PHP code embedded in the extension as a memory buffer, > registered during MINIT, and then executed at each RINIT. This would > probably require a stream wrapper because the opcode cache would require > paths for this code. We can also concatenate the scripts but we still need > a virtual path. The stream wrapper would just be simpler to implement. > This uses the usual "require" functionality that you can call from PHP as well. If the files are not found, then you get an error. > > Regards > > François > >