md_src_php__r_e_a_d_m_e.html 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
  5. <meta http-equiv="X-UA-Compatible" content="IE=9"/>
  6. <meta name="generator" content="Doxygen 1.8.17"/>
  7. <meta name="viewport" content="width=device-width, initial-scale=1"/>
  8. <title>GRPC PHP: Overview</title>
  9. <link href="tabs.css" rel="stylesheet" type="text/css"/>
  10. <script type="text/javascript" src="jquery.js"></script>
  11. <script type="text/javascript" src="dynsections.js"></script>
  12. <link href="search/search.css" rel="stylesheet" type="text/css"/>
  13. <script type="text/javascript" src="search/searchdata.js"></script>
  14. <script type="text/javascript" src="search/search.js"></script>
  15. <link href="doxygen.css" rel="stylesheet" type="text/css" />
  16. </head>
  17. <body>
  18. <div id="top"><!-- do not remove this div, it is closed by doxygen! -->
  19. <div id="titlearea">
  20. <table cellspacing="0" cellpadding="0">
  21. <tbody>
  22. <tr style="height: 56px;">
  23. <td id="projectalign" style="padding-left: 0.5em;">
  24. <div id="projectname">GRPC PHP
  25. &#160;<span id="projectnumber">1.36.1</span>
  26. </div>
  27. </td>
  28. </tr>
  29. </tbody>
  30. </table>
  31. </div>
  32. <!-- end header part -->
  33. <!-- Generated by Doxygen 1.8.17 -->
  34. <script type="text/javascript">
  35. /* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
  36. var searchBox = new SearchBox("searchBox", "search",false,'Search');
  37. /* @license-end */
  38. </script>
  39. <script type="text/javascript" src="menudata.js"></script>
  40. <script type="text/javascript" src="menu.js"></script>
  41. <script type="text/javascript">
  42. /* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
  43. $(function() {
  44. initMenu('',true,false,'search.php','Search');
  45. $(document).ready(function() { init_search(); });
  46. });
  47. /* @license-end */</script>
  48. <div id="main-nav"></div>
  49. <!-- window showing the filter options -->
  50. <div id="MSearchSelectWindow"
  51. onmouseover="return searchBox.OnSearchSelectShow()"
  52. onmouseout="return searchBox.OnSearchSelectHide()"
  53. onkeydown="return searchBox.OnSearchSelectKey(event)">
  54. </div>
  55. <!-- iframe showing the search results (closed by default) -->
  56. <div id="MSearchResultsWindow">
  57. <iframe src="javascript:void(0)" frameborder="0"
  58. name="MSearchResults" id="MSearchResults">
  59. </iframe>
  60. </div>
  61. </div><!-- top -->
  62. <div class="PageDoc"><div class="header">
  63. <div class="headertitle">
  64. <div class="title">Overview </div> </div>
  65. </div><!--header-->
  66. <div class="contents">
  67. <div class="textblock"><p>This directory contains source code for PHP implementation of gRPC layered on shared C library. The same installation guides with more examples and tutorials can be seen at <a href="https://grpc.io/docs/languages/php/quickstart">grpc.io</a>. gRPC PHP installation instructions for Google Cloud Platform is in <a href="https://cloud.google.com/php/grpc">cloud.google.com</a>.</p>
  68. <h1><a class="anchor" id="autotoc_md258"></a>
  69. Environment</h1>
  70. <h2><a class="anchor" id="autotoc_md259"></a>
  71. Prerequisites</h2>
  72. <ul>
  73. <li><code>php</code>: version 7.0 or above (PHP 5.x support is deprecated from Sep 2020).</li>
  74. <li><code>pecl</code></li>
  75. <li><code>composer</code></li>
  76. <li><code>phpunit</code> (optional)</li>
  77. </ul>
  78. <h1><a class="anchor" id="autotoc_md260"></a>
  79. Install the &lt;em&gt;grpc&lt;/em&gt; extension</h1>
  80. <p>There are two ways to install the <code>grpc</code> extension.</p><ul>
  81. <li>Via <code>pecl</code></li>
  82. <li>Build from source</li>
  83. </ul>
  84. <h2><a class="anchor" id="autotoc_md261"></a>
  85. Install from PECL</h2>
  86. <div class="fragment"><div class="line">$ [sudo] pecl install grpc</div>
  87. </div><!-- fragment --><p>or specific version</p>
  88. <div class="fragment"><div class="line">$ [sudo] pecl install grpc-1.30.0</div>
  89. </div><!-- fragment --><p>Please make sure your <code>gcc</code> version satisfies the minimum requirement as specified <a href="https://grpc.io/docs/languages/#official-support">here</a>.</p>
  90. <h2><a class="anchor" id="autotoc_md262"></a>
  91. Install on Windows</h2>
  92. <p>You can download the pre-compiled <code>grpc.dll</code> extension from the PECL <a href="https://pecl.php.net/package/grpc">website</a>.</p>
  93. <h2><a class="anchor" id="autotoc_md263"></a>
  94. Build from source</h2>
  95. <p>Clone this repository at the <a href="https://github.com/grpc/grpc/releases">latest stable release tag</a>.</p>
  96. <div class="fragment"><div class="line">$ git clone -b RELEASE_TAG_HERE https://github.com/grpc/grpc</div>
  97. <div class="line">$ cd grpc</div>
  98. </div><!-- fragment --><h3><a class="anchor" id="autotoc_md264"></a>
  99. Build the gRPC C core library</h3>
  100. <div class="fragment"><div class="line">$ git submodule update --init</div>
  101. <div class="line">$ EXTRA_DEFINES=GRPC_POSIX_FORK_ALLOW_PTHREAD_ATFORK make</div>
  102. </div><!-- fragment --><h3><a class="anchor" id="autotoc_md265"></a>
  103. Build and install the &lt;tt&gt;grpc&lt;/tt&gt; extension</h3>
  104. <p>Compile the <code>grpc</code> extension from source</p>
  105. <div class="fragment"><div class="line">$ grpc_root=&quot;$(pwd)&quot;</div>
  106. <div class="line">$ cd src/php/ext/grpc</div>
  107. <div class="line">$ phpize</div>
  108. <div class="line">$ GRPC_LIB_SUBDIR=libs/opt ./configure --enable-grpc=&quot;${grpc_root}&quot;</div>
  109. <div class="line">$ make</div>
  110. <div class="line">$ [sudo] make install</div>
  111. </div><!-- fragment --><p>This will compile and install the <code>grpc</code> extension into the standard PHP extension directory. You should be able to run the <a href="#unit-tests">unit tests</a>, with the <code>grpc</code> extension installed.</p>
  112. <h2><a class="anchor" id="autotoc_md266"></a>
  113. Update php.ini</h2>
  114. <p>After installing the <code>grpc</code> extension, make sure you add this line to your <code>php.ini</code> file, depending on where your PHP installation is, to enable the <code>grpc</code> extension.</p>
  115. <div class="fragment"><div class="line">extension=grpc.so</div>
  116. </div><!-- fragment --><h1><a class="anchor" id="autotoc_md267"></a>
  117. Composer package</h1>
  118. <p>In addition to the <code>grpc</code> extension, you will need to install the <code>grpc/grpc</code> composer package as well. Add this to your project's <code>composer.json</code> file.</p>
  119. <div class="fragment"><div class="line">&quot;require&quot;: {</div>
  120. <div class="line"> &quot;grpc/grpc&quot;: &quot;~1.30.0&quot;</div>
  121. <div class="line">}</div>
  122. </div><!-- fragment --><p>To run tests with generated stub code from <code>.proto</code> files, you will also need the <code>composer</code> and <code>protoc</code> binaries. You can find out how to get these below.</p>
  123. <h1><a class="anchor" id="autotoc_md268"></a>
  124. Protocol Buffers</h1>
  125. <p>gRPC PHP supports <a href="https://developers.google.com/protocol-buffers">protocol buffers</a> out-of-the-box. You will need the following things to get started:</p>
  126. <ul>
  127. <li><code>protoc</code>: the protobuf compiler binary to generate PHP classes for your messages and service definition.</li>
  128. <li><code>grpc_php_plugin</code>: a plugin for <code>protoc</code> to generate the service stub classes.</li>
  129. <li><code>protobuf.so</code>: the <code>protobuf</code> extension runtime library.</li>
  130. </ul>
  131. <h2><a class="anchor" id="autotoc_md269"></a>
  132. &lt;tt&gt;protoc&lt;/tt&gt; compiler</h2>
  133. <p>If you don't have it already, you need to install the protobuf compiler <code>protoc</code>, version 3.5.0+ (the newer the better) for the current gRPC version. If you installed already, make the protobuf version is compatible to the grpc version you installed. If you build grpc.so from the souce, you can check the version of grpc inside package.xml file.</p>
  134. <p>The compatibility between the grpc and protobuf version is listed as table below:</p>
  135. <table class="markdownTable">
  136. <tr class="markdownTableHead">
  137. <th class="markdownTableHeadNone">grpc </th><th class="markdownTableHeadNone">protobuf </th><th class="markdownTableHeadNone">grpc </th><th class="markdownTableHeadNone">protobuf </th><th class="markdownTableHeadNone">grpc </th><th class="markdownTableHeadNone">protobuf </th></tr>
  138. <tr class="markdownTableRowOdd">
  139. <td class="markdownTableBodyNone">v1.0.0 </td><td class="markdownTableBodyNone">3.0.0(GA) </td><td class="markdownTableBodyNone">v1.12.0 </td><td class="markdownTableBodyNone">3.5.2 </td><td class="markdownTableBodyNone">v1.22.0 </td><td class="markdownTableBodyNone">3.8.0 </td></tr>
  140. <tr class="markdownTableRowEven">
  141. <td class="markdownTableBodyNone">v1.0.1 </td><td class="markdownTableBodyNone">3.0.2 </td><td class="markdownTableBodyNone">v1.13.1 </td><td class="markdownTableBodyNone">3.5.2 </td><td class="markdownTableBodyNone">v1.23.1 </td><td class="markdownTableBodyNone">3.8.0 </td></tr>
  142. <tr class="markdownTableRowOdd">
  143. <td class="markdownTableBodyNone">v1.1.0 </td><td class="markdownTableBodyNone">3.1.0 </td><td class="markdownTableBodyNone">v1.14.2 </td><td class="markdownTableBodyNone">3.5.2 </td><td class="markdownTableBodyNone">v1.24.0 </td><td class="markdownTableBodyNone">3.8.0 </td></tr>
  144. <tr class="markdownTableRowEven">
  145. <td class="markdownTableBodyNone">v1.2.0 </td><td class="markdownTableBodyNone">3.2.0 </td><td class="markdownTableBodyNone">v1.15.1 </td><td class="markdownTableBodyNone">3.6.1 </td><td class="markdownTableBodyNone">v1.25.0 </td><td class="markdownTableBodyNone">3.8.0 </td></tr>
  146. <tr class="markdownTableRowOdd">
  147. <td class="markdownTableBodyNone">v1.2.0 </td><td class="markdownTableBodyNone">3.2.0 </td><td class="markdownTableBodyNone">v1.16.1 </td><td class="markdownTableBodyNone">3.6.1 </td><td class="markdownTableBodyNone">v1.26.0 </td><td class="markdownTableBodyNone">3.8.0 </td></tr>
  148. <tr class="markdownTableRowEven">
  149. <td class="markdownTableBodyNone">v1.3.4 </td><td class="markdownTableBodyNone">3.3.0 </td><td class="markdownTableBodyNone">v1.17.2 </td><td class="markdownTableBodyNone">3.6.1 </td><td class="markdownTableBodyNone">v1.27.3 </td><td class="markdownTableBodyNone">3.11.2 </td></tr>
  150. <tr class="markdownTableRowOdd">
  151. <td class="markdownTableBodyNone">v1.3.5 </td><td class="markdownTableBodyNone">3.2.0 </td><td class="markdownTableBodyNone">v1.18.0 </td><td class="markdownTableBodyNone">3.6.1 </td><td class="markdownTableBodyNone">v1.28.1 </td><td class="markdownTableBodyNone">3.11.2 </td></tr>
  152. <tr class="markdownTableRowEven">
  153. <td class="markdownTableBodyNone">v1.4.0 </td><td class="markdownTableBodyNone">3.3.0 </td><td class="markdownTableBodyNone">v1.19.1 </td><td class="markdownTableBodyNone">3.6.1 </td><td class="markdownTableBodyNone">v1.29.0 </td><td class="markdownTableBodyNone">3.11.2 </td></tr>
  154. <tr class="markdownTableRowOdd">
  155. <td class="markdownTableBodyNone">v1.6.0 </td><td class="markdownTableBodyNone">3.4.0 </td><td class="markdownTableBodyNone">v1.20.1 </td><td class="markdownTableBodyNone">3.7.0 </td><td class="markdownTableBodyNone">v1.30.0 </td><td class="markdownTableBodyNone">3.12.2 </td></tr>
  156. </table>
  157. <p>v1.8.0 | 3.5.0 | v1.21.3 | 3.7.0</p>
  158. <p>If <code>protoc</code> hasn't been installed, you can download the <code>protoc</code> binary from the protocol buffers <a href="https://github.com/google/protobuf/releases">Github repository</a>. Then unzip this file and update the environment variable <code>PATH</code> to include the path to the protoc binary file.</p>
  159. <p>If you really must compile <code>protoc</code> from source, you can run the following commands, but this is risky because there is no easy way to uninstall / upgrade to a newer release.</p>
  160. <div class="fragment"><div class="line">$ cd grpc/third_party/protobuf</div>
  161. <div class="line">$ ./autogen.sh &amp;&amp; ./configure &amp;&amp; make</div>
  162. <div class="line">$ [sudo] make install</div>
  163. </div><!-- fragment --><h2><a class="anchor" id="autotoc_md270"></a>
  164. &lt;tt&gt;grpc_php_plugin&lt;/tt&gt; protoc plugin</h2>
  165. <p>You need the <code>grpc_php_plugin</code> to generate the PHP client stub classes. This plugin works with the main <code>protoc</code> binary to generate classes that you can import into your project.</p>
  166. <p>It should already been compiled when you run <code>make</code> from the root directory of this repo. The plugin can be found in the <code>bins/opt</code> directory. We are planning to provide a better way to download and install the plugin in the future.</p>
  167. <p>You can also just build the <code>grpc_php_plugin</code> by running:</p>
  168. <div class="fragment"><div class="line">$ git clone -b RELEASE_TAG_HERE https://github.com/grpc/grpc</div>
  169. <div class="line">$ cd grpc</div>
  170. <div class="line">$ git submodule update --init</div>
  171. <div class="line">$ make grpc_php_plugin</div>
  172. </div><!-- fragment --><p>Alternatively, you can also build the <code>grpc_php_plugin</code> with <code>bazel</code> now:</p>
  173. <div class="fragment"><div class="line">$ bazel build @com_google_protobuf//:protoc</div>
  174. <div class="line">$ bazel build src/compiler:grpc_php_plugin</div>
  175. </div><!-- fragment --><p>The <code>protoc</code> binary will be found in <code>bazel-bin/external/com_google_protobuf/protoc</code>. The <code>grpc_php_plugin</code> binary will be found in <code>bazel-bin/src/compiler/grpc_php_plugin</code>.</p>
  176. <p>Plugin may use the new feature of the new protobuf version, thus please also make sure that the protobuf version installed is compatible with the grpc version you build this plugin.</p>
  177. <h2><a class="anchor" id="autotoc_md271"></a>
  178. &lt;tt&gt;protobuf&lt;/tt&gt; runtime library</h2>
  179. <p>There are two <code>protobuf</code> runtime libraries to choose from. They are identical in terms of APIs offered. The C implementation provides better performance, while the native implementation is easier to install.</p>
  180. <h3><a class="anchor" id="autotoc_md272"></a>
  181. C implementation (for better performance)</h3>
  182. <p>Install the <code>protobuf</code> extension from PECL:</p>
  183. <div class="fragment"><div class="line">$ [sudo] pecl install protobuf</div>
  184. </div><!-- fragment --><p>or specific version</p>
  185. <div class="fragment"><div class="line">$ [sudo] pecl install protobuf-3.12.2</div>
  186. </div><!-- fragment --><p>And add this to your <code>php.ini</code> file:</p>
  187. <div class="fragment"><div class="line">extension=protobuf.so</div>
  188. </div><!-- fragment --><h3><a class="anchor" id="autotoc_md273"></a>
  189. PHP implementation (for easier installation)</h3>
  190. <p>Or require the <code>google/protobuf</code> composer package. Add this to your <code>composer.json</code> file:</p>
  191. <div class="fragment"><div class="line">&quot;require&quot;: {</div>
  192. <div class="line"> &quot;google/protobuf&quot;: &quot;~v3.12.2&quot;</div>
  193. <div class="line">}</div>
  194. </div><!-- fragment --><h2><a class="anchor" id="autotoc_md274"></a>
  195. Generate PHP classes from your service definition</h2>
  196. <p>With all the above done, now you can define your message and service defintion in a <code>.proto</code> file and generate the corresponding PHP classes, which you can import into your project, with a command similar to the following:</p>
  197. <div class="fragment"><div class="line">$ protoc -I=. echo.proto --php_out=. --grpc_out=. \</div>
  198. <div class="line">--plugin=protoc-gen-grpc=&lt;path to grpc_php_plugin&gt;</div>
  199. </div><!-- fragment --><h1><a class="anchor" id="autotoc_md275"></a>
  200. Unit Tests</h1>
  201. <p>You will need the source code to run tests</p>
  202. <div class="fragment"><div class="line">$ git clone -b RELEASE_TAG_HERE https://github.com/grpc/grpc</div>
  203. <div class="line">$ cd grpc</div>
  204. <div class="line">$ git submodule update --init</div>
  205. </div><!-- fragment --><p>Run unit tests</p>
  206. <div class="fragment"><div class="line">$ cd grpc/src/php</div>
  207. <div class="line">$ ./bin/run_tests.sh</div>
  208. </div><!-- fragment --><h1><a class="anchor" id="autotoc_md276"></a>
  209. Generated Code Tests</h1>
  210. <p>This section specifies the prerequisites for running the generated code tests, as well as how to run the tests themselves.</p>
  211. <h2><a class="anchor" id="autotoc_md277"></a>
  212. Composer</h2>
  213. <p>Install the runtime dependencies via <code>composer install</code>.</p>
  214. <div class="fragment"><div class="line">$ cd grpc/src/php</div>
  215. <div class="line">$ composer install</div>
  216. </div><!-- fragment --><h2><a class="anchor" id="autotoc_md278"></a>
  217. Client Stub</h2>
  218. <p>The generate client stub classes have already been generated from <code>.proto</code> files by the <code>./bin/generate_proto_php.sh</code> script.</p>
  219. <h2><a class="anchor" id="autotoc_md279"></a>
  220. Run test server</h2>
  221. <p>Run a local server serving the <code>Math</code> <a href="https://github.com/grpc/grpc/blob/master/src/proto/math/math.proto#L42">service</a>.</p>
  222. <div class="fragment"><div class="line">$ cd grpc/src/php/tests/generated_code</div>
  223. <div class="line">$ npm install</div>
  224. <div class="line">$ node math_server.js</div>
  225. </div><!-- fragment --><h2><a class="anchor" id="autotoc_md280"></a>
  226. Run test client</h2>
  227. <p>Run the generated code tests</p>
  228. <div class="fragment"><div class="line">$ cd grpc/src/php</div>
  229. <div class="line">$ ./bin/run_gen_code_test.sh</div>
  230. </div><!-- fragment --><h1><a class="anchor" id="autotoc_md281"></a>
  231. Apache, PHP-FPM and Nginx</h1>
  232. <p>For more information on how you can run the <code>grpc</code> library with Apache, PHP-FPM and Nginx, you can check out <a href="https://github.com/grpc/grpc/tree/master/examples/php/echo">this guide</a>. There you will find a series of Docker images where you can quickly run an end-to-end example.</p>
  233. <h1><a class="anchor" id="autotoc_md282"></a>
  234. Misc Config Options</h1>
  235. <h2><a class="anchor" id="autotoc_md283"></a>
  236. SSL credentials</h2>
  237. <p>Here's how you can specify SSL credentials when creating your PHP client:</p>
  238. <div class="fragment"><div class="line">$client = <span class="keyword">new</span> Helloworld\GreeterClient(<span class="stringliteral">&#39;localhost:50051&#39;</span>, [</div>
  239. <div class="line"> <span class="stringliteral">&#39;credentials&#39;</span> =&gt; <a class="code" href="namespace_grpc.html">Grpc</a>\ChannelCredentials::createSsl(</div>
  240. <div class="line"> file_get_contents(<span class="stringliteral">&#39;&lt;path to certificate&gt;&#39;</span>))</div>
  241. <div class="line">]);</div>
  242. </div><!-- fragment --><h2><a class="anchor" id="autotoc_md284"></a>
  243. pcntl_fork() support</h2>
  244. <p>To make sure the <code>grpc</code> extension works with <code>pcntl_fork()</code> and related functions, add the following lines to your <code>php.ini</code> file:</p>
  245. <div class="fragment"><div class="line">grpc.enable_fork_support = 1</div>
  246. <div class="line">grpc.poll_strategy = epoll1</div>
  247. </div><!-- fragment --><h2><a class="anchor" id="autotoc_md285"></a>
  248. Tracing and Logging</h2>
  249. <p>To turn on gRPC tracing, add the following lines to your <code>php.ini</code> file. For all possible values of the <code>grpc.grpc.trace</code> option, please check <a href="https://github.com/grpc/grpc/blob/master/doc/environment_variables.md">this doc</a>.</p>
  250. <div class="fragment"><div class="line">grpc.grpc_verbosity=debug</div>
  251. <div class="line">grpc.grpc_trace=all,-polling,-polling_api,-pollable_refcount,-timer,-timer_check</div>
  252. <div class="line">grpc.log_filename=/var/log/grpc.log</div>
  253. </div><!-- fragment --><blockquote class="doxtable">
  254. <p>Make sure the log file above is writable, by doing the following: </p><div class="fragment"><div class="line">$ sudo touch /var/log/grpc.log</div>
  255. <div class="line">$ sudo chmod 666 /var/log/grpc.log</div>
  256. </div><!-- fragment --><p>Note: The log file does grow pretty quickly depending on how much logs are being printed out. Make sure you have other mechanisms (perhaps another cronjob) to zero out the log file from time to time, e.g. <code>cp /dev/null /var/log/grpc.log</code>, or turn these off when logs or tracing are not necessary for debugging purposes. </p>
  257. </blockquote>
  258. <h2><a class="anchor" id="autotoc_md286"></a>
  259. User agent string</h2>
  260. <p>You can customize the user agent string for your gRPC PHP client by specifying this <code>grpc.primary_user_agent</code> option when constructing your PHP client:</p>
  261. <div class="fragment"><div class="line">$client = <span class="keyword">new</span> Helloworld\GreeterClient(<span class="stringliteral">&#39;localhost:50051&#39;</span>, [</div>
  262. <div class="line"> <span class="stringliteral">&#39;credentials&#39;</span> =&gt; <a class="code" href="namespace_grpc.html">Grpc</a>\ChannelCredentials::createInsecure(),</div>
  263. <div class="line"> <span class="stringliteral">&#39;grpc.primary_user_agent&#39;</span> =&gt; <span class="stringliteral">&#39;my-user-agent-identifier&#39;</span>,</div>
  264. <div class="line">]);</div>
  265. </div><!-- fragment --><h2><a class="anchor" id="autotoc_md287"></a>
  266. Maximum message size</h2>
  267. <p>To change the default maximum message size, specify this <code>grpc.max_receive_message_length</code> option when constructing your PHP client:</p>
  268. <div class="fragment"><div class="line">$client = <span class="keyword">new</span> Helloworld\GreeterClient(<span class="stringliteral">&#39;localhost:50051&#39;</span>, [</div>
  269. <div class="line"> <span class="stringliteral">&#39;credentials&#39;</span> =&gt; <a class="code" href="namespace_grpc.html">Grpc</a>\ChannelCredentials::createInsecure(),</div>
  270. <div class="line"> <span class="stringliteral">&#39;grpc.max_receive_message_length&#39;</span> =&gt; 8*1024*1024,</div>
  271. <div class="line">]);</div>
  272. </div><!-- fragment --><h2><a class="anchor" id="autotoc_md288"></a>
  273. Compression</h2>
  274. <p>You can customize the compression behavior on the client side, by specifying the following options when constructing your PHP client.</p>
  275. <div class="fragment"><div class="line">$client = <span class="keyword">new</span> Helloworld\GreeterClient(<span class="stringliteral">&#39;localhost:50051&#39;</span>, [</div>
  276. <div class="line"> <span class="stringliteral">&#39;credentials&#39;</span> =&gt; <a class="code" href="namespace_grpc.html">Grpc</a>\ChannelCredentials::createInsecure(),</div>
  277. <div class="line"> <span class="stringliteral">&#39;grpc.default_compression_algorithm&#39;</span> =&gt; 2,</div>
  278. <div class="line"> <span class="stringliteral">&#39;grpc.default_compression_level&#39;</span> =&gt; 2,</div>
  279. <div class="line">]);</div>
  280. </div><!-- fragment --><p>Possible values for <code>grpc.default_compression_algorithm</code>:</p>
  281. <div class="fragment"><div class="line">0: No compression</div>
  282. <div class="line">1: Compress with DEFLATE algorithm</div>
  283. <div class="line">2: Compress with GZIP algorithm</div>
  284. <div class="line">3: Stream compression with GZIP algorithm</div>
  285. </div><!-- fragment --><p>Possible values for <code>grpc.default_compression_level</code>:</p>
  286. <div class="fragment"><div class="line">0: None</div>
  287. <div class="line">1: Low level</div>
  288. <div class="line">2: Medium level</div>
  289. <div class="line">3: High level</div>
  290. </div><!-- fragment --> </div></div><!-- contents -->
  291. </div><!-- PageDoc -->
  292. <div class="ttc" id="anamespace_grpc_html"><div class="ttname"><a href="namespace_grpc.html">Grpc</a></div><div class="ttdoc">Class AbstractCall.</div><div class="ttdef"><b>Definition:</b> AbstractCall.php:20</div></div>
  293. <!-- start footer part -->
  294. <hr class="footer"/><address class="footer"><small>
  295. Generated on Wed Mar 3 2021 19:20:18 for GRPC PHP by &#160;<a href="http://www.doxygen.org/index.html">
  296. <img class="footer" src="doxygen.png" alt="doxygen"/>
  297. </a> 1.8.17
  298. </small></address>
  299. </body>
  300. </html>