05.05.2013 Views

Programming PHP

Programming PHP

Programming PHP

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Figure 14-1 shows a diagram of a web server with <strong>PHP</strong> linked in. The web server<br />

layer at the top handles incoming HTTP requests and passes them to <strong>PHP</strong> via the<br />

Server Abstraction API (SAPI). The “mysql”, “ldap”, and “snmp” boxes represent<br />

loadable <strong>PHP</strong> extensions, the kind you’ll learn how to build in this chapter. TSRM is<br />

the Thread Safe Resource Manager layer, which helps simplify thread-safe programming.<br />

The <strong>PHP</strong> Core contains many of the nonoptional core features of <strong>PHP</strong>, and the<br />

<strong>PHP</strong> API contains the <strong>PHP</strong>-specific API functions used by both the core and the <strong>PHP</strong><br />

extensions. Finally, there is the Zend engine, which runs scripts through a two-pass<br />

mechanism, first generating a set of opcodes and then executing them. A <strong>PHP</strong> extension<br />

uses the Zend extension API to receive arguments from function calls and return<br />

values back.<br />

Figure 14-1. Structure of a <strong>PHP</strong>-linked web server<br />

What You’ll Need<br />

To develop a <strong>PHP</strong> extension, you’ll need a copy of the <strong>PHP</strong> source code and various<br />

software development tools, as discussed below.<br />

The <strong>PHP</strong> Source<br />

TSRM<br />

Fetch a copy of the current CVS version of the <strong>PHP</strong> code, to ensure that you are<br />

using the most up-to-date version of the API. See http://cvs.php.net for instructions<br />

on how to obtain the CVS version of the code via anonymous CVS.<br />

<strong>PHP</strong> comes with a skeleton extension framework generator called ext_skel; this little<br />

script is a lifesaver. You should spend some time studying the README.EXT_SKEL<br />

and README.SELF-CONTAINED-EXTENSIONS files that come with the <strong>PHP</strong><br />

source code.<br />

The <strong>PHP</strong> source code offers you dozens of example extensions to look at. Each subdirectory<br />

in the ext/ directory contains a <strong>PHP</strong> extension. Chances are that just about<br />

anything you need to implement will in some way resemble one of the existing<br />

318 | Chapter 14: Extending <strong>PHP</strong><br />

<strong>PHP</strong> core<br />

Web server<br />

SAPI<br />

<strong>PHP</strong> API<br />

mysql ldap snmp<br />

Zend API Zend extension API<br />

Zend engine<br />

Runtime<br />

compiler<br />

Executer<br />

This is the Title of the Book, eMatter Edition<br />

Copyright © 2002 O’Reilly & Associates, Inc. All rights reserved.<br />

TSRM

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!