<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                ## PHP TCP 服務是基于 Socket 開發的,因此客戶端我們能直接使用 PHP 的 Socket 操作方法連接,得益于 [Swoole 的 Hook](https://wiki.swoole.com/wiki/page/p-runtime.html) 技術 (mix 默認已經開啟 Hook) ,PHP 的原生 Socket 操作可在協程中使用。 - 將下面代碼保存為 `client.php`: > 其中 EOF 要與 TCP 服務器的 [StartCommand:class](https://github.com/mix-php/mix-skeleton/tree/v2.1/app/Tcp/Commands/StartCommand.php#L40) 中一至 ~~~ <?php /** * Class JsonRpcTcpClient * @author liu,jian <coder.keda@gmail.com> */ class JsonRpcTcpClient { /** * @var resource */ public $socket; /** * @var string */ public $eof = "\n"; /** * @var int */ public $timeout = 5; /** * @var int */ public $lineMaxLength = 4096; /** * JsonRpcTcpClient constructor. * @param string $host * @param int $port */ public function __construct(string $host, int $port) { $socket = stream_socket_client("tcp://{$host}:{$port}", $errno, $errstr, $this->timeout); if (!$socket) { throw new \RuntimeException("JSON-RPC tcp client connection failed, [$errno] {$errstr}"); } $this->socket = $socket; } /** * 執行方法 * @param string $method * @param array $params * @param int $id * @return array */ public function call(string $method, array $params, int $id = 0) { $ret = fwrite($this->socket, json_encode([ 'method' => $method, 'params' => $params, 'id' => $id, ]) . $this->eof); if ($ret === false) { throw new \RuntimeException('JSON-RPC tcp client write failed.'); } stream_set_timeout($this->socket, $this->timeout); $data = stream_get_line($this->socket, $this->lineMaxLength, $this->eof); if ($data === false) { throw new \RuntimeException('JSON-RPC tcp client read failed.'); } return json_decode($data, true); } /** * Destruct */ public function __destruct() { // TODO: Implement __destruct() method. fclose($this->socket); } } // 執行RPC $client = new JsonRpcTcpClient('127.0.0.1', 9503); $result = $client->call('foo.bar', [], 123); var_dump($result); ~~~ **1. 啟動服務器** ~~~ php bin/mix.php tcp:start ~~~ **2. 執行 `client.php`** ~~~ php client.php ~~~ 接收到加入成功的消息: ~~~ [root@localhost data]# php client.php array(4) { ["jsonrpc"]=> string(3) "2.0" ["error"]=> NULL ["result"]=> array(1) { [0]=> string(13) "Hello, World!" } ["id"]=> int(123) } ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看