Navigate to the ext/ folder under your PHP source tree and execute the following command:
jdoe@devbox:/home/jdoe/cvs/php-src/ext/$ ./ext_skel extname=sample7
After a few moments and a little bit of text, you'll receive some instructions along the lines of the following:
To use your new extension, you will have to execute the following steps: 1. $ cd .. 2. $ vi ext/sample7/config.m4 3. $ ./buildconf 4. $ ./configure [with|enable]-sample7 5. $ make 6. $ ./php -f ext/sample7/sample7.php 7. $ vi ext/sample7/sample7.c 8. $ make Repeat steps 3-6 until you are satisfied with ext/sample7/config.m4 and step 6 confirms that your module is compiled into PHP. Then, start writing code and repeat the last two steps as often as necessary.
Looking in ext/sample7 at this point, you'll see a verbosely commented version of the files you first put together in Chapter 5, "Your First Extension." As it stands you won't be able to compile your extension just yet; however, with just a little bit of work massaging config.m4 as the instructions state, you should be off and running with an extension that accomplishes nearly as much as you originally wrote in Chapter 5.
Generating Function Prototypes
If you're writing an extension to wrap a third-party library, you already have a machine readable version of what the functions need to look like and what their basic behavior needs to be. By passing one extra parameter to ./ext_skel, it will automatically scan your header file and create simple PHP_FUNCTION() blocks to accommodate the interface. Try it out by instructing ./ext_skel to parse the zlib headers:
jdoe@devbox:/home/jdoe/cvs/php-src/ext/$ ./ext_skel extname=sample8 proto=/usr/local/include/zlib/zlib.h
Glancing inside ext/sample8/sample8.c now, you'll find more than a dozen PHP_FUNCTION() declarations, one for each zlib function. Notice, however, that the skeleton generation process issued some warning messages about unknown resource types. You'll need to pay particular attention to these functions and apply some of the experience you gained in Chapter 9, "The Resource Data Type," in order to link the internal complex structures to userspace accessible variables.