This is an old revision of the document!
PHP RFC: Add PHP files to auto_prepend from extensions
- Version: 0.1
- Date: 2015-01-04
- Author: Benjamin Eberlei firstname.lastname@example.org
- Status: Discussion
It should be possible to ship PHP Extensions that contain both C and PHP code to achieve their goal. While C code is obviously much faster, for many extensions it is viable to build glue code, useful wrappers and performance uncritical code using PHP.
The auto_prepend mechanism is improved to contain a list of files to pass to zend_execute_scripts instead of just using the INI value for auto_prepend.
If a php.ini value for auto_prepend is configured it will be loaded after all the PHP files registered by extensions.
This functionality can be achieved already using RINIT to emulate this sort of behavior. The following three extensions use this sort of behavior:
- Qafoo Profiler
- Z-Ray (Verified as per they docs only)
Others have expressed their wish to use this feature.
Using RINIT is error prone and a little bit dangerous, because is a bit too early for some data to be cleanly created (globals).
Adding this kind of API in a straightforward way would allow extension authors to make use of PHP for parts of their project. This simplifies installation for users.
The exact changes are up for discussion, this is how I propose it might work:
- Introduce a global list of files to include from extensions.
- Change php_execute_scripts (main/main.c) + zend_execute_scripts to access global list for including files.
- Add API that extensions can use during MINIT to add files to the global list.
The API of zend_execute_scripts needs to change for this:
-ZEND_API int zend_execute_scripts(int type, zval *retval, int file_count, ...); +ZEND_API int zend_execute_scripts(int type, zval *retval, zend_file_handle **files);
We can introduce a new function zend_execute_script that can be used by code that called zend_execute_scripts before:
ZEND_API int zend_execute_script(int type, zval *retval, zend_file_handle *file);
Then php_execute_scripts can build the list of files from extension prepends, ini prepend, primary file and append files.
Backward Incompatible Changes
Proposed PHP Version(s)
SAPIs must not be updated *unless* they use zend_execute_scripts directly.
To Existing Extensions
Not verified, but given the locality of the change in php_execute_scripts and reusing of an exisitig feature, it does not seem likely to break.
Unaffected PHP Functionality
- SAPIs are unaffected by this change unless they use zend_execute_scripts directly.
- Opcache is unaffected by this change.
- Extensions are unaffected by this change.
Proposed Voting Choices
This will be a yes/no vote with 50%+1 majority, because it is not a public API to change only introducing a new one in the Engine Core.
Patches and Tests
Working on a prototype.
v0.1.1: Fix typo in code example.