05.05.2013 Views

Programming PHP

Programming PHP

Programming PHP

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

examples, and you are strongly encouraged to steal/borrow as much existing code as<br />

possible (with proper attribution, of course).<br />

Software Tools<br />

To write an extension, you need to have working versions of these tools installed:<br />

• bison<br />

• flex<br />

• m4<br />

• autoconf<br />

• automake<br />

• libtool<br />

• An ANSI-compliant compiler such as gcc<br />

• make<br />

• sed, awk, and Perl are also used optionally here and there<br />

These are all standard tools available free on the Internet (see http://www.gnu.org for<br />

most of them). If you are running a Linux distribution or any of the BSD operating<br />

systems, follow your distribution’s mechanism for installing new packages. In Windows,<br />

you can install the cygwin environment to run tools such as bison, flex, and<br />

autoconf, doing the final build using Microsoft Visual DevStudio.<br />

Building Your First Extensions<br />

This section walks you through the steps of building your first extension, from<br />

design through testing. Most extensions are created by writing a file that defines the<br />

functions the extension will have, building a skeleton from that, and then filling in<br />

the C code that does the actual work of the extension. This section doesn’t cover<br />

advanced topics such as returning complex values or managing memory—we’ll talk<br />

about those later, after you have the basics down.<br />

Command-Line <strong>PHP</strong><br />

Unless your extension can really be tested only through the Web, it is much easier to<br />

debug and quickly test your code through the command-line version of <strong>PHP</strong> (also<br />

sometimes referred to as the CGI version of <strong>PHP</strong>). To build the command-line version,<br />

do something like this:<br />

% cd php4<br />

% ./configure --with-mysql=/usr --with-pgsql --with-zlib --with-config-file=/etc<br />

% make<br />

# make install<br />

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

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

Building Your First Extensions | 319

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

Saved successfully!

Ooh no, something went wrong!