aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/php/tests/generated_code
diff options
context:
space:
mode:
authorGravatar Stanley Cheung <stanleycheung@google.com>2015-09-21 16:28:59 -0700
committerGravatar Stanley Cheung <stanleycheung@google.com>2015-09-22 10:01:08 -0700
commite4c47389633a7fd741fadee15e54d6eb3fb09570 (patch)
treed90dd183efa96dbded4a587652373f73217ed644 /src/php/tests/generated_code
parent493fd972826a04083cd31ae1c0154b649c1264aa (diff)
php: add examples for apache and nginx
Diffstat (limited to 'src/php/tests/generated_code')
-rw-r--r--src/php/tests/generated_code/math_client.php70
1 files changed, 70 insertions, 0 deletions
diff --git a/src/php/tests/generated_code/math_client.php b/src/php/tests/generated_code/math_client.php
new file mode 100644
index 0000000000..cbf6cd618b
--- /dev/null
+++ b/src/php/tests/generated_code/math_client.php
@@ -0,0 +1,70 @@
+<?php
+
+# Fix the following two lines to point to your installation
+include 'vendor/autoload.php';
+include 'tests/generated_code/math.php';
+
+function p($line) {
+ print("$line<br/>\n");
+}
+
+h$host = "localhost:50051";
+p("Connecting to host: $host");
+$client = new math\MathClient($host, []);
+p("Client class: ".get_class($client));
+p('');
+
+p("Running unary call test:");
+$dividend = 7;
+$divisor = 4;
+$div_arg = new math\DivArgs();
+$div_arg->setDividend($dividend);
+$div_arg->setDivisor($divisor);
+$call = $client->Div($div_arg);
+p("Call peer: ".$call->getPeer());
+p("Dividing $dividend by $divisor");
+list($response, $status) = $call->wait();
+p("quotient = ".$response->getQuotient());
+p("remainder = ".$response->getRemainder());
+p('');
+
+p("Running server streaming test:");
+$limit = 7;
+$fib_arg = new math\FibArgs();
+$fib_arg->setLimit($limit);
+$call = $client->Fib($fib_arg);
+$result_array = iterator_to_array($call->responses());
+$result = '';
+foreach ($result_array as $num) {
+ $result .= ' ' . $num->getNum();
+}
+p("The first $limit Fibonacci numbers are:".$result);
+p('');
+
+p("Running client streaming test:");
+$call = $client->Sum();
+for ($i = 0; $i <= $limit; $i++) {
+ $num = new math\Num();
+ $num->setNum($i);
+ $call->write($num);
+}
+list($response, $status) = $call->wait();
+p(sprintf("The first %d positive integers sum to: %d",
+ $limit, $response->getNum()));
+p('');
+
+p("Running bidi-streaming test:");
+$call = $client->DivMany();
+for ($i = 0; $i < 7; $i++) {
+ $div_arg = new math\DivArgs();
+ $dividend = 2 * $i + 1;
+ $div_arg->setDividend($dividend);
+ $divisor = 3;
+ $div_arg->setDivisor($divisor);
+ $call->write($div_arg);
+ p("client writing: $dividend / $divisor");
+ $response = $call->read();
+ p(sprintf("server writing: quotient = %d, remainder = %d",
+ $response->getQuotient(), $response->getRemainder()));
+}
+$call->writesDone();