PHP: Using Extensions - Manual
PHP  
downloads | documentation | faq | getting help | mailing lists | | php.net sites | links | my php.net 
search for in the  
<Creating ExtensionsTroubleshooting>
view the version of this page
Last updated: Tue, 21 Dec 2004

第 48章Using Extensions

Depending on the build process you selected, you should either end up with a new PHP binary to be linked into your Web server (or run as CGI), or with an .so (shared object) file. If you compiled the example file first_module.c as a shared object, your result file should be first_module.so. To use it, you first have to copy it to a place from which it's accessible to PHP. For a simple test procedure, you can copy it to your htdocs directory and try it with the source in 例48-1. If you compiled it into the PHP binary, omit the call to dl(), as the module's functionality is instantly available to your scripts.

警告

For security reasons, you should not put your dynamic modules into publicly accessible directories. Even though it can be done and it simplifies testing, you should put them into a separate directory in production environments.

例 48-1. A test file for first_module.so.

<?php
  
// remove next comment if necessary
// dl("first_module.so");

$param = 2;
$return = first_module($param);

print(
"We sent '$param' and got '$return'");

?>

Calling this PHP file in your Web browser should give you the output shown in 図48-1.

図 48-1. Output of first_module.php.

If required, the dynamic loadable module is loaded by calling the dl() function. This function looks for the specified shared object, loads it, and makes its functions available to PHP. The module exports the function first_module(), which accepts a single parameter, converts it to an integer, and returns the result of the conversion.

If you've gotten this far, congratulations! You just built your first extension to PHP.



add a note add a note User Contributed Notes
Using Extensions
There are no user contributed notes for this page.

<Creating ExtensionsTroubleshooting>
 Last updated: Tue, 21 Dec 2004
show source | credits | sitemap | contact | advertising | mirror sites 
Copyright © 2001-2005 The PHP Group
All rights reserved.
This unofficial mirror is operated at: /
Last updated: Mon Mar 14 08:13:06 2005 Local time zone must be set--see zic manual page