瀏覽代碼

:building_construction: add php-grpc demo

Jeremy Zheng 2 年之前
父節點
當前提交
e5dc0817bd
共有 6 個文件被更改,包括 46 次插入0 次删除
  1. 2 0
      clients/php/.gitignore
  2. 9 0
      clients/php/README.md
  3. 14 0
      clients/php/composer.json
  4. 二進制
      clients/php/documents/client.png
  5. 二進制
      clients/php/documents/server.png
  6. 21 0
      clients/php/morus-demo.php

+ 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/"
+    }
+  }
+}

二進制
clients/php/documents/client.png


二進制
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!');