PageRenderTime 44ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/Docs/phpAPI.html

http://github.com/yahoo/Pluton
HTML | 263 lines | 210 code | 53 blank | 0 comment | 0 complexity | 25d6183b703f6351a53fd448c91d9462 MD5 | raw file
  1. <html>
  2. <head>
  3. <link rel="shortcut icon" href=images/pluto-symbol.jpg type="image/x-icon" />
  4. <title>
  5. The Pluton Framework: PHP API
  6. </title>
  7. </head>
  8. <body>
  9. <center>
  10. <a href=index.html>
  11. <img height=100 src=images/pluto-charon.jpg ALT="[Pluto Charon Image]">
  12. </a>
  13. </center>
  14. <h2 align=center>The Pluton Framework: PHP API</h2>
  15. <h3>Introduction</h3>
  16. The PHP API is a <a href=http://www.zend.com>ZEND</a> extension
  17. around the C++ <a href=clientAPI.html>client</a> and
  18. <a href=serviceAPI.html>service</a> APIs.
  19. The PHP API is semantically very similar to its C++ counterparts; the main differences being
  20. the parameters passed to the APIs.
  21. <p>
  22. This document highlights the differences between the C++ API and the
  23. PHP API. For a more complete description of each of the APIs please
  24. refer the C++ <a href=clientAPI.html>client</a>
  25. and <a href=serviceAPI.html>service</a> APIs.
  26. <h3>Sample Programs</h3>
  27. This sample php client demonstrates sending a
  28. request to the <code>system.echo.0.raw</code> service.
  29. <p>
  30. <table border=1 width="75%">
  31. <td>
  32. <pre>
  33. &lt;?php
  34. define('SERVICE_KEY', 'test.parrot.0.raw');
  35. $pc = new PlutonClient('echoClient');
  36. $pc->initialize();
  37. $echoReq = new PlutonClientRequest();
  38. /* Set the request data */
  39. $echoReq->setRequestData("Hello World!");
  40. /* Add the request to the queue */
  41. if(!($pc->addRequest(SERVICE_KEY, $echoReq))) {
  42. print_r("[addRequest Error] " . $pc->getFault() . "\n");
  43. exit(-1);
  44. }
  45. /* Execute the request */
  46. $pc->executeAndWaitAll();
  47. if ($pc->hasFault()) {
  48. print_r("[Fault] " . $pc->getFault() . "\n");
  49. exit(-1);
  50. }
  51. $response = "";
  52. /* Extract the response data */
  53. $fault = $echoReq->getResponseData($response);
  54. if ($fault == 0) {
  55. print_r("Response: " . $response . "\n");
  56. }
  57. else {
  58. print_r("[Fault] " . $echoReq->getFaultText() . "\n");
  59. }
  60. ?&gt;
  61. </pre>
  62. </table>
  63. <p>
  64. Its corresponding service looks like:
  65. <p>
  66. <table border=1 width="75%">
  67. <td>
  68. <pre>
  69. &lt;?php
  70. // Create and initialize the Pluton service.
  71. $service = new PlutonService('test.parrot.0.raw');
  72. $service->initialize();
  73. // Invoke the call loop.
  74. while($service->getRequest()) {
  75. // Call received, deserialize the request.
  76. $request = trim($service->getRequestData());
  77. if($request === 'fault') {
  78. $service->sendFault(11, 'You asked for a fault...so here you go');
  79. }
  80. else {
  81. if(!$service->sendResponse($request)) {
  82. $service->sendFault(11, 'sendResponse() failed');
  83. }
  84. }
  85. }
  86. // Call loop completed, see if the loop exited early due to a fault.
  87. if($service->hasFault()) {
  88. // Call loop exited because of a fault.
  89. error_log('Service had a fault');
  90. }
  91. // Terminate the service.
  92. $service->terminate();
  93. // Exit code zero indicating no major failure.
  94. exit(0);
  95. ?&gt;
  96. </pre>
  97. </table>
  98. <h3>ClientRequest</h3>
  99. <p>
  100. <b>Class:</b> PlutonClientRequest
  101. <p>
  102. The following table lists the PHP Client and Service APIs available and the differences that
  103. exists between them and the C++ counterparts.
  104. <p>
  105. <table border=1>
  106. <tr valign=top><th align=left>PHP ClientRequest Methods<th align=left>Same as C++<th align=left>Comments</tr>
  107. <tr valign=top><th align=left><a href=clientAPI.html#clearAttribute>clearAttribute()</a><td>Yes<td></tr>
  108. <tr valign=top><th align=left><a href=clientAPI.html#getAttribute>getAttribute()</a><td>Yes<td></tr>
  109. <tr valign=top><th align=left><a href=clientAPI.html#getClientHandle>getClientHandle()</a><td>Yes<td>Note that the client handle is a 32 bit integer</tr>
  110. <tr valign=top><th align=left><a href=clientAPI.html#getFaultCode>getFaultCode()</a><td>Yes<td></tr>
  111. <tr valign=top><th align=left><a href=clientAPI.html#getFaultText>getFaultText()</a><td>Yes<td></tr>
  112. <tr valign=top><th align=left><a href=clientAPI.html#getResponseData>getResponseData()</a><td>Yes<td></tr>
  113. <tr valign=top><th align=left><a href=clientAPI.html#getServiceName>getServiceName()</a><td>Yes<td></tr>
  114. <tr valign=top><th align=left><a href=clientAPI.html#hasFault>hasFault()</a><td>Yes<td></tr>
  115. <tr valign=top><th align=left><a href=clientAPI.html#inProgress>inProgress()</a><td>Yes<td></tr>
  116. <tr valign=top><th align=left><a href=clientAPI.html#requestReset>reset()</a><td>Yes<td></tr>
  117. <tr valign=top><th align=left><a href=clientAPI.html#setAttribute>setAttribute()</a><td>Yes<td>
  118. <pre>
  119. The attribute names differ from their C++ counterparts:<br/>
  120. PLUTON_ALL_ATTR --> pluton::allAttrs
  121. PLUTON_KEEPAFFINITY_ATTR --> pluton::keepAffinityAttr
  122. PLUTON_NEEDAFFINITY_ATTR --> pluton::needAffinityAttr
  123. PLUTON_NOREMOTE_ATTR --> pluton::noRemoteAttr
  124. PLUTON_NORETRY_ATTR --> pluton::noRetryAttr
  125. PLUTON_NOWAIT_ATTR --> pluton::noWaitAttr
  126. </pre>
  127. </tr>
  128. <tr valign=top><th align=left><a href=clientAPI.html#setClientHandle>setClientHandle()</a><td>Yes<td>Note that the client handle is a 32 bit integer</tr>
  129. <tr valign=top><th align=left><a href=clientAPI.html#setContext>setContext()</a><td>Yes<td></tr>
  130. <tr valign=top><th align=left><a href=clientAPI.html#setRequestData>setRequestData()</a><td>Yes<td></tr>
  131. </table>
  132. <h3>Client Methods</h3>
  133. <b>Class:</b> PlutonClient
  134. <p>
  135. The following table lists the PlutonClient methods available as part of the PHP
  136. APIs.
  137. <p>
  138. <table border=1>
  139. <tr valign=top><th align=left>PHP API<th align=left>Same as C++<th align=left>Comments</tr>
  140. <tr valign=top><th align=left><a href=clientAPI.html#addRequest>addRequest()</a><td>Yes<td>Supplied parameter is a reference to a<code>PlutonClientRequest</code></tr>
  141. <tr valign=top><th align=left><a href=clientAPI.html#clientGetFault>getFault()</a><td>No<td>Returns the long fault message (without prefix) from the <a href=fault.html><code>pluton::fault</code></a> object associated with this client object</tr>
  142. <tr valign=top><th align=left><a href=fault.html#getFaultCode>getFaultCode()</a><td>New<td>Returns the fault code from the associated <a href=fault.html><code>pluton::fault</code></a> object associated with the PHP <code>PlutonClient</code> object</tr>
  143. <tr valign=top><th align=left><a href=fault.html#getMessage>getFaultMessage()</a><td>New<td>Returns the fault message from the associated <a href=fault.html><code>pluton::fault</code></a> object associated with the PHP <code>PlutonClient</code> object. The parameters to this method are the same as <a href=fault.html#getMessage><code>pluton::fault::getMessage()</code></a></tr>
  144. <tr valign=top><th align=left><a href=clientAPI.html#clientHasFault>hasFault()</a><td>Yes<td></tr>
  145. <tr valign=top><th align=left><a href=clientAPI.html#executeAndWaitAll>executeAndWaitAll()</a><td>Yes<td></tr>
  146. <tr valign=top><th align=left><a href=clientAPI.html#executeAndWaitAny>executeAndWaitAny()</a><td>No<td>Return value is clientHandle of completed request or zero if no request completed.<br>Note that the semantics of this call are experimental and may change to more accurately reflect the C++ interface.</tr>
  147. <tr valign=top><th align=left><a href=clientAPI.html#executeAndWaitOne>executeAndWaitOne()</a><td>Yes<td>Supplied parameter is a <code>PlutonClientRequest</code> object</tr>
  148. <tr valign=top><th align=left><a href=clientAPI.html#executeAndWaitSent>executeAndWaitSent()</a><td>Yes<td></tr>
  149. <tr valign=top><th align=left><a href=clientAPI.html#getAPIVersion>getAPIVersion()</a><td>Yes<td></tr>
  150. <tr valign=top><th align=left><a href=clientAPI.html#getTimeoutMilliSeconds>getTimeoutMilliSeconds()</a><td>Yes<td></tr>
  151. <tr valign=top><th align=left><a href=clientAPI.html#initialize>initialize()</a><td>Yes<td></tr>
  152. <tr valign=top><th align=left><a href=clientAPI.html#setDebug>setDebug()</a><td>Yes<td></tr>
  153. <tr valign=top><th align=left><a href=clientAPI.html#setTimeoutMilliSeconds>setTimeoutMilliSeconds()</a><td>Yes<td></tr>
  154. <tr valign=top><th align=left><a href=clientAPI.html#clientReset>reset()</a><td>Yes<td></tr>
  155. </table>
  156. <h3>Service Methods</h3>
  157. <b>Class:</b> PlutonService
  158. <p>
  159. <p>
  160. <table border=1>
  161. <tr valign=top><th align=left>PHP APIs<th align=left>Same as C++<th align=left>Comments</tr>
  162. <tr valign=top><th align=left><a href=serviceAPI.html#getAPIVersion>getAPIVersion()</a><td>Yes<td></tr>
  163. <tr valign=top><th align=left><a href=serviceAPI.html#getClientName>getClientName()</a><td>No<td>No parameter is passed to this routine</tr>
  164. <tr valign=top><th align=left><a href=serviceAPI.html#getContext>getContext()</a><td>No<td>No second parameter is passed to this routine - Context data is the return value, eg:
  165. <br>
  166. <pre>
  167. $cd = $r->getContextData("echo.timeoutMS");
  168. print_r "Context data is $cd\n";
  169. </pre>
  170. </tr>
  171. <tr valign=top><th align=left><a href=serviceAPI.html#serviceGetFault>getFault()</a><td>No<td>
  172. Returns the long fault message (without prefix) from
  173. the <a href=fault.html><code>pluton::fault</code></a> object associated
  174. with this service object</tr>
  175. <tr valign=top><th align=left><a href=fault.html#getFaultCode>getFaultCode()</a><td>New<td>
  176. Returns the fault code from the
  177. associated <a href=fault.html><code>pluton::fault</code></a> object
  178. associated with this service object</tr>
  179. <tr valign=top><th align=left><a href=fault.html#getMessage>getFaultMessage()</a><td>New<td>
  180. Returns the fault message from the
  181. associated <a href=fault.html><code>pluton::fault</code></a> object
  182. associated with this service object. The
  183. parameters to this method are the same as <a href=fault.html#getMessage><code>pluton::fault::getMessage()</code></a></tr>
  184. </tr>
  185. <tr valign=top><th align=left><a href=serviceAPI.html#getRequest>getRequest()</a><td>Yes<td></tr>
  186. <tr valign=top><th align=left><a href=serviceAPI.html#getRequestData>getRequestData()</a><td>No<td>No parameter is passed to this routine - Request data is the return value</tr>
  187. <tr valign=top><th align=left><a href=serviceAPI.html#getSerializationType>getSerializationType()</a><td>Yes<td></tr>
  188. <tr valign=top><th align=left><a href=serviceAPI.html#getServiceApplication>getServiceApplication()</a><td>No<td>No parameter is passed to this routine</tr>
  189. <tr valign=top><th align=left><a href=serviceAPI.html#getServiceFunction>getServiceFunction()</a><td>No<td>No parameter is passed to this routine</tr>
  190. <tr valign=top><th align=left><a href=serviceAPI.html#getServiceKey>getServiceKey()</a><td>No<td>No parameter is passed to this routine</tr>
  191. <tr valign=top><th align=left><a href=serviceAPI.html#getServiceVersion>getServiceVersion()</a><td>Yes<td></tr>
  192. <tr valign=top><th align=left><a href=serviceAPI.html#hasFault>hasFault()</a><td>Yes<td></tr>
  193. <tr valign=top><th align=left><a href=serviceAPI.html#initialize>initialize()</a><td>Yes<td></tr>
  194. <tr valign=top><th align=left><a href=serviceAPI.html#sendFault>sendFault()</a><td>Yes<td></tr>
  195. <tr valign=top><th align=left><a href=serviceAPI.html#sendResponse>sendResponse()</a><td>Yes<td>Only the single parameter version available, eg:<br>
  196. <pre>
  197. $s = new PlutonService();
  198. $s->sendResponse("Here is some data");
  199. <pre>
  200. </tr>
  201. <tr valign=top><th align=left><a href=serviceAPI.html#terminate>terminate()</a><td>Yes<td></tr>
  202. </table>
  203. <p>
  204. <hr>
  205. <font size=-1>
  206. $Id: phpAPI.html 263414 2009-12-01 00:52:44Z markd $
  207. &copy; Copyright Yahoo! Inc, 2008, 2009
  208. </font>
  209. </body>
  210. </html>