<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>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                # package_length_func 設置長度解析函數,支持C++或PHP的2種類型的函數。長度函數必須返回一個整數。 * 返回`0`,數據不足,需要接收更多數據 * 返回`-1`,數據錯誤,底層會自動關閉連接 * 返回包長度值(包括包頭和包體的總長度),底層會自動將包拼好后返回給回調函數 默認底層最大會讀取`8K`的數據,如果包頭的長度較小可能會存在內存復制的消耗。可設置`package_body_offset`參數,底層只讀取包頭進行長度解析。 PHP長度解析函數 ---- 由于`ZendVM`不支持運行在多線程環境,因此底層會自動使用`Mutex`互斥鎖對`PHP`長度函數進行加鎖,避免并發執行`PHP`函數。在`1.9.3`或更高版本可用。 > 請勿在長度解析函數中執行阻塞`IO`操作,可能導致所有`Reactor`線程發生阻塞 ```php $serv = new swoole_server("127.0.0.1", 9501); $serv->set(array( 'open_length_check' => true, 'dispatch_mode' => 1, 'package_length_func' => function ($data) { if (strlen($data) < 8) { return 0; } $length = intval(trim(substr($data, 0, 8))); if ($length <= 0) { return -1; } return $length + 8; }, 'package_max_length' => 2000000, //協議最大長度 )); $serv->on('receive', function (swoole_server $serv, $fd, $from_id, $data) { var_dump($data); echo "#{$serv->worker_id}>> received length=" . strlen($data) . "\n"; }); $serv->start(); ``` C++長度解析函數 ---- 在其他PHP擴展中,使用`swoole_add_function`注冊長度函數到`Swoole`引擎中。 > C++長度函數調用時底層不會加鎖,需要調用方自行保證線程安全性 ### 實例: ```php #include <string> #include <iostream> #include "swoole.h" using namespace std; int test_get_length(swProtocol *protocol, swConnection *conn, char *data, uint32_t length); void register_length_function(void) { swoole_add_function((char *) "test_get_length", (void *) test_get_length); return SW_OK; } int test_get_length(swProtocol *protocol, swConnection *conn, char *data, uint32_t length) { printf("cpp, size=%d\n", length); return 100; } ```
                  <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>

                              哎呀哎呀视频在线观看