Extending PHP
By Sterling Hughes
As my grandfather always says, "If you want something done right, do it yourself." However, these days you often have to rely on third-party tools to help you get your job done. To serve even a simple, static HTML Web page you need to rely on your Web server, which in turn relies on your operating system, and so on. While you can't create all these programs yourself, most of the ones that you rely onyour Web server, for exampleprovide an API to help you extend and add functionality to these programs, so if they don't meet your needs you can always modify them.
PHPor more properly the PHP Hypertext Preprocessorlets you easily create dynamic Web sites by embedding code into the Web page (HTML) itself. This open-source software is very popular on the Web where open-source products like Apache and Perl predominate. While PHP offers considerable power as a scripting language, its true power lies in the fact that if it doesn't offer what you need, you can easily extend it with either C or C++. To extend PHP 4, you need to understand the PHP API (more specifically the Zend API, since PHP 4 is powered by the Zend Engine).
A Quick Overview
Before you extend PHP, you should understand how Zend and PHP interact. There are several steps:
- The user makes an ordinary request to the Web server.
- The Web server sends the request to PHP.
- PHP calls the Server API layer.
The Zend Engine compiles and executes the script, using any enabled extension modules.<>