<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、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                [TOC] * * * * * ## 1 源代碼 ~~~ Worker.php public function __construct($socket_name = '', $context_option = array()) { // Save all worker instances. $this->workerId = spl_object_hash($this); self::$_workers[$this->workerId] = $this; self::$_pidMap[$this->workerId] = array(); // Get autoload root path. $backrace = debug_backtrace(); $this->_autoloadRootPath = dirname($backrace[0]['file']); // Context for socket. if ($socket_name) { $this->_socketName = $socket_name; if (!isset($context_option['socket']['backlog'])) { $context_option['socket']['backlog'] = self::DEFAUL_BACKLOG; } $this->_context = stream_context_create($context_option); } // Set an empty onMessage callback. $this->onMessage = function () { }; } ~~~ ## 2 分析 ### 1 函數接口 `__construct($socket_name = '', $context_option = array())` > $socket_name: <協議>://<監聽地址>類參數 > $context_option: socket的上下文選項 * * * * * >> <協議> 可以為以下格式: > tcp: 例如 tcp://0.0.0.0:8686 > udp: 例如 udp://0.0.0.0:8686 > unix: 例如 unix:///tmp/my_file (需要Workerman>=3.2.7) > http: 例如 http://0.0.0.0:80 > websocket: 例如 websocket://0.0.0.0:8686 > text: 例如 text://0.0.0.0:8686 * * * * * >> <監聽地址> 可以為以下格式: > 如果是unix套接字,地址為本地一個磁盤路徑 > 非unix套接字,地址格式為 <本機ip>:<端口號> > <本機ip>可以為0.0.0.0表示監聽本機所有網卡,包括內網ip和外網ip及本地回環127.0.0.1 > <本機ip>如果以為127.0.0.1表示監聽本地回環,只能本機訪問,外部無法訪問 > <本機ip>如果為內網ip,類似192.168.xx.xx,表示只監聽內網ip,則外網用戶無法訪問 > <本機ip>設置的值不屬于本機ip則無法執行監聽,并且提示Cannot assign requested address錯誤 > 注意:<端口號>不能大于65535。<端口號>如果小于1024則需要root權限才能監聽。監聽的端口必須是本機未被占用的端口,否則無法監聽,并且提示Address already in use錯誤 * * * * * > $context_option: 套接字選項見 基礎原理 socket上下文選項呢 ### 2 函數分析 ~~~ $this->workerId = spl_object_hash($this); self::$_workers[$this->workerId] = $this; self::$_pidMap[$this->workerId] = array(); ~~~ 1 分配workeId 設置workerId。spl_object_hash()函數獲取對象的hash值。 spl_object_hash()見 基礎原理 基礎函數 注冊workerId到$_workers和$_pidMap ~~~ $backrace = debug_backtrace(); $this->_autoloadRootPath = dirname($backrace[0]['file']); ~~~ 2 設置自動加載根目錄 debug_backtrace() 見 基礎函數 dirname()返回文件目錄信息 見 基礎函數 ~~~ if ($socket_name) { $this->_socketName = $socket_name; if (!isset($context_option['socket']['backlog'])) { $context_option['socket']['backlog'] = self::DEFAUL_BACKLOG; } $this->_context = stream_context_create($context_option); } ~~~ 3 設置socket上下文。 設置_socketName 檢查socket的backlog選項,見 socket上下文選項 最后調用straem_context_create() 創建資源流上下文 stream_context_create() 見 socket上下文選項 ~~~ $this->onMessage = function () { }; ~~~ 4 注冊默認的onMessage接口函數 `$worker->count = 8;` 5 設置啟動進程數 ## 3 總結 構造函數完成worker的基礎屬性設置 >[info] 1 workerId分配 >[info] 2 加載根目錄 >[info] 3 socket上下文選項 >[info] 4 注冊OnMessage回調接口 >[info] 5 設置啟動進程數
                  <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>

                              哎呀哎呀视频在线观看