Sophie

Sophie

distrib > Mandriva > 9.1 > ppc > media > main > by-pkgid > 0afeee9cca140e167a996902b9a677c5 > files > 3273

php-manual-en-4.3.0-2mdk.noarch.rpm

<HTML
><HEAD
><TITLE
>Using Extensions</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK
REL="HOME"
TITLE="PHP Manual"
HREF="index.html"><LINK
REL="UP"
TITLE="Extending PHP 4.0"
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=ISO-8859-1"></HEAD
><BODY
CLASS="chapter"
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 Manual</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="zend.creating.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="zend.troubleshooting.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="chapter"
><H1
><A
NAME="zend.using"
>Chapter 29. 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"
>Example 29-1</A
>. 
   If you compiled it into the PHP binary,
   omit the call to <A
HREF="function.dl.html"
><B
CLASS="function"
>dl()</B
></A
>, 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
>Warning</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
>Example 29-1. A test file for first_module.so.</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="php"
>&#60;?php
    
// remove next comment if necessary
// dl("first_module.so"); 

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

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

?&#62;</PRE
></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
><P
>&#13;   Calling this PHP file in your Web browser should give you the 
   output shown in <A
HREF="zend.using.html#fig.out-first"
>Figure 29-1</A
>. 
   <DIV
CLASS="figure"
><A
NAME="fig.out-first"
></A
><P
><B
>Figure 29-1. Output of first_module.php.</B
></P
><P
><IMG
SRC="figures/Extending_Zend_2_firstmod_output.png"></P
></DIV
>
  </P
><P
>&#13;   If required, the dynamic loadable module is loaded by calling the
   <A
HREF="function.dl.html"
><B
CLASS="function"
>dl()</B
></A
> 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"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="zend.troubleshooting.html"
ACCESSKEY="N"
>Next</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"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>Troubleshooting</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>