rfc:remove_zend_api
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
rfc:remove_zend_api [2009/04/05 15:37] – Re-organization of first half, and small edits. pbiggar | rfc:remove_zend_api [2017/09/22 13:28] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== | + | ====== |
- | * Version: 1.0 | + | * Version: 1.1 |
* Date: 2009-03-27 | * Date: 2009-03-27 | ||
* Author: Paul Biggar < | * Author: Paul Biggar < | ||
- | * Status: | + | |
- | + | ||
- | + | ||
- | A better way to provide a C API, with particular emphasis on decoupling extensions from the interpreter. | + | |
===== Introduction ===== | ===== Introduction ===== | ||
- | This RFC is in two parts, which will probably be split off in the future: | + | Currently, PHP's interpreter, |
- | * The need to remove | + | This RFC does not describe how to remove access, and what to replace it with. That is described separately, in [[php_native_interface]]. |
- | * The design | + | |
Line 32: | Line 28: | ||
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 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, | + | 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, |
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: | 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: | ||
Line 41: | Line 37: | ||
- | The second half of this RFC describes a solution to this issue: the 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, | ||
- | |||
- | |||
- | ===== phpni: The PHP Native Interface ===== | ||
- | |||
- | This describes the design of *phpni*, the PHP Native Interface. This design is in early stages. The stages required until completion are described later (link?). | ||
- | |||
- | |||
- | === Design Criteria === | ||
- | |||
- | * Remove any couping between the Zend Engine, extensions and SAPIs. | ||
- | * Support all major use cases of the Zend API | ||
- | * embedding within SAPIs | ||
- | * proving access to C libraries | ||
- | * providing the ability to rewrite performance sensitive code in C | ||
- | |||
- | |||
- | === Solution === | ||
- | |||
- | Take the use case of wrapping a C library to expose its functionality in user space. The major idea is to " | ||
- | |||
- | Lets take a simple example. Assume we have a C library XXX, with 3 functions, x, y and z. We'd like to expose this in user space as a class called MyXXX, with methods a and b. We create a file with the signatures of x, y and z: | ||
- | |||
- | extensions/ | ||
- | < | ||
- | int x (int, int); | ||
- | void y (char*, int); | ||
- | void z (char*, int); | ||
- | </ | ||
- | |||
- | We then write our user space code: | ||
- | |||
- | extensions/ | ||
- | < | ||
- | class MyXXX | ||
- | { | ||
- | | ||
- | { | ||
- | | ||
- | } | ||
- | |||
- | | ||
- | { | ||
- | $foo = \internals\XXX\x ($w1, $w2); | ||
- | \internals\XXX\y ($this-> | ||
- | } | ||
- | |||
- | | ||
- | { | ||
- | $foo = \internals\XXX\x ($m1, $m2); | ||
- | \internals\XXX\z ($this-> | ||
- | return $foo; | ||
- | } | ||
- | } | ||
- | </ | ||
- | |||
- | In order to interface between these two, it will be necessary to have a tool to automatically wrap the C functions. SWIG could be used to create this tool. | ||
- | |||
- | === Zend engine === | ||
- | |||
- | Since the libraries would no longer use the Zend API, the tight coupling would be broken. It would now be possible to change major parts of the Zend engine without affecting the operation of any other part of PHP. | ||
- | |||
- | === Extensions/ | ||
- | |||
- | It would no longer be necessary to know the Zend API to write extensions. Instead, only the API of the C library is necessary, and the interface can be created in PHP user code. | ||
- | |||
- | === Embed SAPI === | ||
- | |||
- | The same interface used for libraries can be used to handle many of the use cases of the C API. However, it is likely that a means to call PHP user code from C/C++ code, will be required. | ||
- | |||
- | |||
- | === Other PHP implementations === | ||
- | |||
- | Since PHP extensions are no longer written in the Zend API, other PHP implementations, | ||
- | |||
- | |||
- | ===== Similar projects ===== | ||
- | |||
- | === Non-PHP === | ||
- | |||
- | phpni differs from many of these in that it is designed not to add new features, but instead to replace an existing facility - the ability to call C libraries. As such, dynamic linking is not part of the spec. | ||
- | |||
- | * ctypes (Python) http:// | ||
- | * JNI (Java) http:// | ||
- | * CNI (Java) http:// | ||
- | * JNA (Java) https:// | ||
- | * Pyrex (Python) http:// | ||
- | * Cython (Python) http:// | ||
- | * FFI (ruby) http:// | ||
- | * Haskell 98 Foreign Function Interface http:// | ||
- | * CFFI (Common Lisp): Common-Lisp FFI: http:// | ||
- | |||
- | === For PHP === | ||
- | |||
- | There is no reason we shouldn' | ||
- | |||
- | * FFI http:// | ||
- | * CodeGen_PECL http:// | ||
- | * Inline_C http:// | ||
- | | ||
- | |||
- | ===== 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: | ||
- | |||
- | * Prototype a single library | ||
- | * perhaps readline? | ||
- | * Manually write interface code between the header and the PHP code. | ||
- | * Discuss requirements with other PHP implementations | ||
- | | ||
- | * Write a utility to generate the interface code automatically | ||
- | * Using SWIG? | ||
- | * Test 5 or 6 libraries | ||
- | * Test more complicated functionality | ||
- | * Convert entire set of PHP extensions | + | ===== How to proceed ====== |
- | Naturally, before | + | A proposed replacement for the Zend API is described in [[php_native_interface]]. However, |
+ | 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]]. | ||
rfc/remove_zend_api.1238945851.txt.gz · Last modified: 2017/09/22 13:28 (external edit)