Просмотр исходного кода

:building_construction: add php-grpc demo

Jeremy Zheng 2 лет назад
Родитель
Сommit
e5dc0817bd

+ 2 - 0
clients/php/.gitignore

@@ -0,0 +1,2 @@
+/vendor/
+/composer.lock

+ 9 - 0
clients/php/README.md

@@ -0,0 +1,9 @@
+# USAGE
+
+![server](documents/server.png)
+
+```bash
+php -d extension=grpc.so -d max_execution_time=300 morus-demo.php
+```
+
+![client](documents/client.png)

+ 14 - 0
clients/php/composer.json

@@ -0,0 +1,14 @@
+{
+  "require": {
+    "grpc/grpc": "v1.57.0",
+    "google/protobuf": "v3.23.2"
+  },
+  "autoload": {
+    "psr-4": {
+      "GPBMetadata\\": [
+        "GPBMetadata/"
+      ],
+      "Mint\\": "Mint/"
+    }
+  }
+}

BIN
clients/php/documents/client.png


BIN
clients/php/documents/server.png


+ 21 - 0
clients/php/morus-demo.php

@@ -0,0 +1,21 @@
+<?php
+
+require dirname(__FILE__) . '/vendor/autoload.php';
+
+function md2htm($host, $text)
+{
+    $client = new Mint\Morus\V1\MarkdownClient($host, [
+        'credentials' => Grpc\ChannelCredentials::createInsecure(),
+    ]);
+    $request = new Mint\Morus\V1\MarkdownToHtmlRequest();
+    $request->setPayload($text);
+    $request->setSanitize(true);
+    list($response, $status) = $client->ToHtml($request)->wait();
+    if ($status->code !== Grpc\STATUS_OK) {
+        echo "ERROR: " . $status->code . ", " . $status->details . PHP_EOL;
+        exit(1);
+    }
+    echo $response->getPayload() . PHP_EOL;
+}
+
+md2htm('localhost:9999', '# Hi, mint!');