Removal of the Zend API
- Version: 1.1
- Date: 2009-03-27
- Author: Paul Biggar paul.biggar@gmail.com
- Status: Brainstorming: http://wiki.php.net/rfc/remove_zend_api/scratchpad
Introduction
Currently, PHP's interpreter, the Zend Engine, provides access to its internals via the Zend API. This RFC provides a rationale for this access, by removing the Zend API.
This RFC does not describe how to remove access, and what to replace it with. That is described separately, in php_native_interface. The goals of this RFC are predicated on achieving the goals of php_native_interface.
Why remove the Zend API?
Zend API
The Zend API is a large set of functions, macros and data-structures which are used to interact with the Zend Engine. It serves 3 major purposes, roughly in order of importance:
- Used to write PHP's standard libraries, 3rd party extensions, and much of PECL.
- Allows wrapping of C/C++ libraries in order to allow the to be accessed from user-code.
- Allows hot (performance-sensitive) code to be rewritten in C for speed
- Used to embed PHP into within C/C++ applications using the embed SAPI
Problems
The main problem with it is that it constrains the implementation of the Zend Engine. The Zend API creates a tight coupling between the Zend Engine and its clients, restricting greatly our ability to change the Zend Engine. By requiring backwards compatability with the Zend Engine, we are ensuring that the Zend Engine can only be modified in minor ways. This holds the Zend Engine to design decisions made nearly 10 years ago, and prevents PHP from getting much faster in the long term.
The Zend API also makes it difficult to write PHP extensions. Although most of the API is not terribly difficult to work with, concepts like copy-on-write, change-on-write sets, and separation appear to be tricky concepts for many people. The only documentation is Sara Golemon's book, and the actual code is not well commented. Although zend_parse_parameters() has simplified the parameter parsing somewhat, it seems that a simpler way of writing extensions would be welcome.
A number of other PHP implementations exist, such as IBM's Project Zero, Phalanger, Roadsend, Quercus and phc. Many of these projects find it very difficult to re-use PHP's standard libraries. They have chosen different strategies:
- Quercus and Roadsend have reimplemented popular extensions. This means that probably 90% of extensions are unavailable. It also means that future and private extensions cannot be available.
- Phalanger and Project Zero attempt to re-use the existing libraries by marshalling their data into the Zend API. This appears to be slow and error-prone. In particular, Project Zero reports speed problems from marshalling Unicode strings into the Zend API (and those are then passed to C libraries, possably requiring extra marshaling).
- phc is designed around reusing the Zend API for compatibility with the PHP. This constrains many of the optimizations phc would wish to perform.
How to proceed
A proposed replacement for the Zend API is described in php_native_interface. However, to actually solve this issue, a decision must be made to not only use the PHP Native Interface to provide an interface between extensions and implementations, but also to disallow any external access to the Zend API.
This RFC is a means of achieving concensus on removing the Zend API in PHP 6, predicated on first achieving the goals in php_native_interface.