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.

if (extension_loaded($module)) {<br />

$str = $function($module);<br />

} else {<br />

$str = "Module $module is not compiled into <strong>PHP</strong>";<br />

}<br />

echo "$str\n";<br />

?><br />

This code checks to see an if the extension is loaded, lists the functions provided by<br />

the extension, and then calls the confirmation function if the extension was loaded.<br />

This is good, but it doesn’t test whether the rot13( ) function works.<br />

Modify the test script to look like this:<br />

<br />

Run the test with:<br />

% ~/php4/ext/rot13> php -q rot13.php<br />

Enfzhf Rasmus<br />

The test program encrypts “Rasmus”, then uses rot13( ) on the string again to<br />

decrypt it. The -q option tells the command-line version of <strong>PHP</strong> to not display any<br />

HTTP headers.<br />

The config.m4 File<br />

The config.m4 file contains the code that will go into the configure script. This<br />

includes the switch that enables the extension (e.g., --enable-rot13 or --with-rot13),<br />

the name of the shared library to build, code to search for prerequisite libraries, and<br />

much more. The skeletal config.m4 file contains sample code for the various things<br />

you might want to do, commented out.<br />

There are conventions governing the configure switch to enable your extension. If<br />

your extension does not rely on any external components, use --enable-foo. Ifit<br />

does have some nonbundled dependencies, such as a library, use --with-foo.<br />

Optionally, you can specify a base path using --with-foo=/some/path, which helps<br />

configure find the dependencies.<br />

<strong>PHP</strong> uses the grand unifying scheme of autoconf, automake, and libtool to build<br />

extensions. These three tools, used together, can be extremely powerful, but they can<br />

also be extremely frustrating. Getting this stuff right is a bit of a black art. When an<br />

extension is part of the <strong>PHP</strong> source tree and you run the buildconf script in the top<br />

directory of the tree, it scans through all its subdirectories looking for config.m4 files.<br />

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

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

The config.m4 File | 327

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

Saved successfully!

Ooh no, something went wrong!