cvs: peardoc /en/package/webservices/xml-rpc2 cachedclient.xml

From: Date: Sat, 22 Apr 2006 11:43:32 +0000
Subject: cvs: peardoc /en/package/webservices/xml-rpc2 cachedclient.xml
Groups: php.pear.doc 
Request: Send a blank email to pear-doc+get-7811@lists.php.net to get a copy of this message
fab Sat Apr 22 11:43:32 2006 UTC Modified files: /peardoc/en/package/webservices/xml-rpc2 cachedclient.xml Log: first draft http://cvs.php.net/viewcvs.cgi/peardoc/en/package/webservices/xml-rpc2/cachedclient.xml?r1=1.1&r2=1.2&diff_format=u Index: peardoc/en/package/webservices/xml-rpc2/cachedclient.xml diff -u peardoc/en/package/webservices/xml-rpc2/cachedclient.xml:1.1 peardoc/en/package/webservices/xml-rpc2/cachedclient.xml:1.2 --- peardoc/en/package/webservices/xml-rpc2/cachedclient.xml:1.1 Sun Feb 12 00:52:19 2006 +++ peardoc/en/package/webservices/xml-rpc2/cachedclient.xml Sat Apr 22 11:43:32 2006 @@ -1,4 +1,4 @@ -<!-- $Revision: 1.1 $ --> +<!-- $Revision: 1.2 $ --> <refentry id="package.webservices.xml-rpc2.cachedclient"> <refnamediv> @@ -6,14 +6,185 @@ <refpurpose></refpurpose> </refnamediv> - <refsect1 id="package.webservices.xml-rpc2.cachedclient.general"> - <title>to be written</title> - + <refsect1 id="package.webservices.xml-rpc2.cachedclient.intro"> + <title>Introduction about the XML_RPC2 "cached client side" usage</title> + <para> + Thanks to PHP5 and PEAR/Cache_Lite, it's really easy to do XMLRPC "cached client" requests with + XML_RPC2. The usage is really straightforward. + </para> + <para> + First, you include 'XML/RPC2/CachedClient.php' file (only this one). + <programlisting role="php"> + <![CDATA[ +require_once 'XML/RPC2/CachedClient.php'; + ]]> + </programlisting> + </para> + <para> + Second, you make an assocative arrays of options to tune XML_RPC2 (prefix, + proxy, manual backend choice...). + <programlisting role="php"> + <![CDATA[ +$options = array( + 'prefix' => 'package.', + 'cacheOptions' => array( + 'cacheDir' => '/tmp/', + 'lifetime' => 3600 + ) +); + ]]> + </programlisting> + </para> + <para> + Third, you make a XML_RPC2_CachedClient object with the server URL and the with + the options array. + <programlisting role="php"> + <![CDATA[ +$client = XML_RPC2_CachedClient::create('http://pear.php.net/xmlrpc.php', $options); + ]]> + </programlisting> + </para> + <para> + Then, you send your request by calling the server method as it was a local + method of the $client object. + <programlisting role="php"> + <![CDATA[ +$result = $client->info('XML_RPC2'); + ]]> + </programlisting> + This single line will encode a XMLRPC client request for the package.info() (prefix + method name) + method with a single argument (the string 'XML_RPC2'), will send the request over HTTP to the + server and will decode the response into PHP native types. With a single line ! Moreover, the result + will be cached into a file for the given lifetime. So the next call will not send any HTTP request + and it will be really fast. + </para> + <para> + Of course, to catch server errors, you have to add a few lines around you client call like for example : + <programlisting role="php"> + <![CDATA[ +try { + $result = $client->info('XML_RPC2'); + print_r($result); +} catch (XML_RPC2_FaultException $e) { + // The XMLRPC server returns a XMLRPC error + die('Exception #' . $result->getFaultCode() . ' : ' . $e->getFaultString()); +} catch (Exception $e) { + // Other errors (HTTP or networking problems...) + die('Exception : ' . $e->getFaultString()); +} + ]]> + </programlisting> + </para> + </refsect1> + <refsect1 id="package.webservices.xml-rpc2.cachedclient.options"> + <title>The options array</title> + <para> + This array is completely optional but really usefull. The following keys + are available : + <table> + <title>Options available keys</title> + <tgroup cols="4"> + <thead> + <row> + <entry>Option</entry> + <entry>Data Type</entry> + <entry>Default Value</entry> + <entry>Description</entry> + </row> + </thead> + <tbody> + <row> + <entry>[...]</entry> + <entry>[...]</entry> + <entry>[...]</entry> + <entry>See "non cached client side" for more options</entry> + </row> + <row> + <entry>cacheOptions</entry> + <entry>&type.array;</entry> + <entry>array()</entry> + <entry>See next table for a complete description</entry> + </row> + </tbody> + </tgroup> + </table> + "CacheOptions" entry is an associative array. Available keys are : + <table> + <title>CacheOptions available keys</title> + <tgroup cols="4"> + <thead> + <row> + <entry>Option</entry> + <entry>Data Type</entry> + <entry>Default Value</entry> + <entry>Description</entry> + </row> + </thead> + <tbody> + <row> + <entry>[...]</entry> + <entry>[...]</entry> + <entry>[...]</entry> + <entry>See "Cache_Lite constructor" for more options</entry> + </row> + <row> + <entry>defaultCacheGroup</entry> + <entry>&type.string;</entry> + <entry>''</entry> + <entry>Name of the default cache group</entry> + </row> + <row> + <entry>cachedMethods</entry> + <entry>&type.array;</entry> + <entry>array()</entry> + <entry>Array of method names to be cached (if cacheByDefault is false)</entry> + </row> + <row> + <entry>notCachedMethods</entry> + <entry>&type.array;</entry> + <entry>array()</entry> + <entry>Array of method names not to be cached (if cacheByDefault is true)</entry> + </row> + <row> + <entry>cacheByDefault</entry> + <entry>&type.bool;</entry> + <entry>&true;</entry> + <entry> + if true, the cache is "on" by default ; else, only methods listed in cachedMethods + will be cached + </entry> + </row> + </tbody> + </tgroup> + </table> + </para> + </refsect1> + <refsect1 id="package.webservices.xml-rpc2.cachedclient.create"> + <title>Making the XML_RPC2_CachedClient object</title> + <para> + It's really easy to make the XML_RPC2_CachedClient object. Use the following syntax : + <programlisting role="php"> + <![CDATA[ +// $XMLRPCServerURL is a string : 'http://pear.php.net/xmlrpc.php' (for example) +// $options is an optional array : see previous section for more informations +$client = XML_RPC2_CachedClient::create($XMLRPCServerURL, $options); + ]]> + </programlisting> + Don't try to call the XML_RPC2_CachedClient constructor directly, use the call() static method. + </para> + </refsect1> + <refsect1 id="package.webservices.xml-rpc2.cachedclient.call"> + <title>Call the XMLRPC exported method</title> + <para> + See "non cached client side" documentation, there is no difference. + </para> <para> - to be written + The caching process is completly embedded and automatic. If a cache is available, result + will be get from cache and no HTTP request will be sent. If there is no cache available for + this particular call (method name and arguments), the classical XMLRPC communication will + be used (and the result will be stored into a cache file for the next use). </para> </refsect1> - </refentry> <!-- Keep this comment at the end of the file

« previous php.pear.doc (#7811) next »