<HTML ><HEAD ><TITLE >PHP $B$G$N(B XML-RPC $B$N;H$$J}(B</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.54"><LINK REL="HOME" TITLE="XML-RPC HOWTO" HREF="index.html"><LINK REL="PREVIOUS" TITLE="Java $B$G$N(B XML-RPC $B$N;H$$J}(B" HREF="xmlrpc-howto-java.html"><LINK REL="NEXT" TITLE="Microsoft .NET $B$G$N(B XML-RPC $B$N;H$$J}(B" HREF="xmlrpc-howto-dotnet.html"></HEAD ><BODY CLASS="SECTION" BGCOLOR="#FFFFFF" TEXT="#000000" ><DIV CLASS="NAVHEADER" ><TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" >XML-RPC HOWTO</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="xmlrpc-howto-java.html" >Prev</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="xmlrpc-howto-dotnet.html" >Next</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><DIV CLASS="SECTION" ><H1 CLASS="SECTION" ><A NAME="XMLRPC-HOWTO-PHP" >10. PHP $B$G$N(B XML-RPC $B$N;H$$J}(B</A ></H1 ><P >Edd Dumbill $B$O(B PHP $BMQ(B XML-RPC $B$r<BAu$7$F$$$^$9!#(B<A HREF="http://xmlrpc.usefulinc.com/" TARGET="_top" >UsefulInc XML-RPC $B%&%'%V%5%$%H(B</A >$B$+$i%@%&%s%m!<%I$G$-$^$9!#(B </P ><P >$BG[I[J*$r%$%s%9%H!<%k$9$k$K$O!"$=$l$r2rE`$7$F!"(B <TT CLASS="FILENAME" >xmlrpc.inc</TT > $B$H(B <TT CLASS="FILENAME" >xmlrpcs.inc</TT > $B$r$"$J$?$N(B PHP $B%9%/%j%W%H$,F~$C$F$$$k$N$HF1$8%G%#%l%/%H%j$K%3%T!<$7(B $B$^$9!#(B</P ><DIV CLASS="SECTION" ><H2 CLASS="SECTION" ><A NAME="XMLRPC-HOWTO-PHP-CLIENT" >10.1. PHP $B%/%i%$%"%s%H(B</A ></H2 ><P >$B<!$N%9%/%j%W%H$O%&%'%V%Z!<%8$NCf$K(B XML-RPC $B%3!<%k$rAH$_9~$`(B $BJ}K!$r<($7$^$9!#(B</P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" WIDTH="100%" ><TR ><TD ><FONT COLOR="#000000" ><PRE CLASS="PROGRAMLISTING" ><html> <head> <title>XML-RPC PHP Demo</title> </head> <body> <h1>XML-RPC PHP Demo</h1> <?php include 'xmlrpc.inc'; // Make an object to represent our server. $server = new xmlrpc_client('/api/sample.php', 'xmlrpc-c.sourceforge.net', 80); // Send a message to the server. $message = new xmlrpcmsg('sample.sumAndDifference', array(new xmlrpcval(5, 'int'), new xmlrpcval(3, 'int'))); $result = $server->send($message); // Process the response. if (!$result) { print "<p>Could not connect to HTTP server.</p>"; } elseif ($result->faultCode()) { print "<p>XML-RPC Fault #" . $result->faultCode() . ": " . $result->faultString(); } else { $struct = $result->value(); $sumval = $struct->structmem('sum'); $sum = $sumval->scalarval(); $differenceval = $struct->structmem('difference'); $difference = $differenceval->scalarval(); print "<p>Sum: " . htmlentities($sum) . ", Difference: " . htmlentities($difference) . "</p>"; } ?> </body></html></PRE ></FONT ></TD ></TR ></TABLE ><P >$B$"$J$?$N%&%'%V%5!<%P$,(B PHP $B%9%/%j%W%H$r<B9T$7$J$$>l9g!"DI2C(B $B>pJs$rF@$k$?$a$K(B <A HREF="http://www.php.net/" TARGET="_top" >PHP $B$N%&%'%V%5%$%H(B</A >$B$r8+$F$/$@$5$$!#(B</P ></DIV ><DIV CLASS="SECTION" ><H2 CLASS="SECTION" ><A NAME="XMLRPC-HOWTO-PHP-SERVER" >10.2. PHP $B%5!<%P(B</A ></H2 ><P >$B<!$N%9%/%j%W%H$O(B PHP $B$rMxMQ$7$?(B XML-RPC $B%5!<%P$N<BAu$NJ}K!$r(B $B<($7$^$9!#(B</P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" WIDTH="100%" ><TR ><TD ><FONT COLOR="#000000" ><PRE CLASS="PROGRAMLISTING" ><?php include 'xmlrpc.inc'; include 'xmlrpcs.inc'; function sumAndDifference ($params) { // Parse our parameters. $xval = $params->getParam(0); $x = $xval->scalarval(); $yval = $params->getParam(1); $y = $yval->scalarval(); // Build our response. $struct = array('sum' => new xmlrpcval($x + $y, 'int'), 'difference' => new xmlrpcval($x - $y, 'int')); return new xmlrpcresp(new xmlrpcval($struct, 'struct')); } // Declare our signature and provide some documentation. // (The PHP server supports remote introspection. Nifty!) $sumAndDifference_sig = array(array('struct', 'int', 'int')); $sumAndDifference_doc = 'Add and subtract two numbers'; new xmlrpc_server(array('sample.sumAndDifference' => array('function' => 'sumAndDifference', 'signature' => $sumAndDifference_sig, 'docstring' => $sumAndDifference_doc))); ?></PRE ></FONT ></TD ></TR ></TABLE ><P >$B$"$J$?$ODL>o!"(B <TT CLASS="LITERAL" >http://localhost/path/sumAndDifference.php</TT > $B$N$h(B $B$&$J$b$N$r8F$S=P$9$G$7$g$&!#(B</P ></DIV ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="xmlrpc-howto-java.html" >Prev</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" >Home</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="xmlrpc-howto-dotnet.html" >Next</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >Java $B$G$N(B XML-RPC $B$N;H$$J}(B</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" > </TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >Microsoft .NET $B$G$N(B XML-RPC $B$N;H$$J}(B</TD ></TR ></TABLE ></DIV ></BODY ></HTML >