rfc:remove_zend_api

This is an old revision of the document!


Removal of the Zend API

Introduction

This RFC provides a rationale for removing external access to the Zend Engine (aka remove the Zend API).

See also 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.

A proposed replacement for the Zend API is described in php_native_interace. 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.

Project Plan

This is a simple design. In reality, it would need to be prototyped to determine whether this makes sense for every use case, and that there would be little sacrificed to make it work. The work on it should probably progress in roughly the following order:

  • Follow the Project Plan in php_native_interface
  • Convert all PHP extensions

Naturally, before the last step it will be necessary to get consensus from other internals developers that this is a good idea.

rfc/remove_zend_api.1238957286.txt.gz · Last modified: 2017/09/22 13:28 (external edit)