Sophie

Sophie

distrib > Mandriva > 2008.1 > x86_64 > by-pkgid > 05cd670d8a02b2b4a0ffb1756f2e8308 > files > 11873

php-manual-zh-5.2.4-1mdv2008.1.noarch.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML
><HEAD
><TITLE
>Using Extensions</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
REL="HOME"
TITLE="PHP 手册"
HREF="index.html"><LINK
REL="UP"
TITLE="Zend API:深入 PHP 内核"
HREF="zend.html"><LINK
REL="PREVIOUS"
TITLE="Creating Extensions"
HREF="zend.creating.html"><LINK
REL="NEXT"
TITLE="Troubleshooting"
HREF="zend.troubleshooting.html"><META
HTTP-EQUIV="Content-type"
CONTENT="text/html; charset=UTF-8"></HEAD
><BODY
CLASS="sect1"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>PHP 手册</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="zend.creating.html"
ACCESSKEY="P"
>上一页</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
>章 46. Zend API:深入 PHP 内核</TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="zend.troubleshooting.html"
ACCESSKEY="N"
>下一页</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="sect1"
><H1
CLASS="sect1"
><A
NAME="zend.using"
>Using Extensions</A
></H1
><P
>&#13;   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 <TT
CLASS="filename"
>first_module.c</TT
> as a shared object, your result file
   should be <TT
CLASS="filename"
>first_module.so</TT
>. 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 <TT
CLASS="filename"
>htdocs</TT
> directory and try it with
   the source in <A
HREF="zend.using.html#example.testfile"
>例 46-3</A
>. 
   If you compiled it into the PHP binary,
   omit the call to <B
CLASS="function"
>dl()</B
>, as the module's
   functionality is instantly available to your scripts. 
   <DIV
CLASS="warning"
><P
></P
><TABLE
CLASS="warning"
BORDER="1"
WIDTH="100%"
><TR
><TD
ALIGN="CENTER"
><B
>警告</B
></TD
></TR
><TR
><TD
ALIGN="LEFT"
><P
>&#13;     For security reasons, you <SPAN
CLASS="emphasis"
><I
CLASS="emphasis"
>should not</I
></SPAN
> put your
     dynamic modules into publicly accessible directories. Even though it <SPAN
CLASS="emphasis"
><I
CLASS="emphasis"
>can</I
></SPAN
> be
     done and it simplifies testing, you should put them into a separate directory
     in production environments.
    </P
></TD
></TR
></TABLE
></DIV
>
  </P
><TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="example.testfile"
></A
><P
><B
>例 46-3. A test file for first_module.so.</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><code><font color="#000000">
<font color="#0000BB">&lt;?php<br />&nbsp;&nbsp;&nbsp;&nbsp;<br /></font><font color="#FF8000">// remove next comment if necessary<br />// dl("first_module.so"); <br /><br /></font><font color="#0000BB">$param </font><font color="#007700">= </font><font color="#0000BB">2</font><font color="#007700">;<br /></font><font color="#0000BB">$return </font><font color="#007700">= </font><font color="#0000BB">first_module</font><font color="#007700">(</font><font color="#0000BB">$param</font><font color="#007700">);<br /><br />print(</font><font color="#DD0000">"We sent '$param' and got '$return'"</font><font color="#007700">);<br /><br /></font><font color="#0000BB">?&gt;</font>
</font>
</code></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
><P
>&#13;   Calling this PHP file should output the following:

We sent '2' and got '2'

  </P
><P
>&#13;   If required, the dynamic loadable module is loaded by calling the
   <B
CLASS="function"
>dl()</B
> function. This function looks for the
   specified shared object, loads it, and makes its functions
   available to PHP. The module exports the function
   <B
CLASS="function"
>first_module()</B
>, which accepts a single
   parameter, converts it to an integer, and returns the result of the
   conversion.
  </P
><P
>&#13;   If you've gotten this far, congratulations! You just built your
   first extension to PHP.
  </P
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="zend.creating.html"
ACCESSKEY="P"
>上一页</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>起始页</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="zend.troubleshooting.html"
ACCESSKEY="N"
>下一页</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>Creating Extensions</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="zend.html"
ACCESSKEY="U"
>上一级</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>Troubleshooting</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>