<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、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                # swoole_server::__construct 創建一個異步`Server`對象。 ```php $serv = new swoole_server(string $host, int $port = 0, int $mode = SWOOLE_PROCESS, int $sock_type = SWOOLE_SOCK_TCP); ``` 參數 ---- * `$host`參數用來指定監聽的ip地址,如`127.0.0.1`,或者外網地址,或者`0.0.0.0`監聽全部地址 * IPv4使用 `127.0.0.1`表示監聽本機,`0.0.0.0`表示監聽所有地址 * IPv6使用`::1`表示監聽本機,`::` (相當于`0:0:0:0:0:0:0:0`) 表示監聽所有地址 * `$port`監聽的端口,如`9501` - 如果`$sock_type`為`UnixSocket Stream/Dgram`,此參數將被忽略 - 監聽小于`1024`端口需要`root`權限 - 如果此端口被占用`server->start`時會失敗 * `$mode`運行的模式 - `SWOOLE_PROCESS`多進程模式(默認) - `SWOOLE_BASE`基本模式 * `$sock_type`指定`Socket`的類型,支持`TCP`、`UDP`、`TCP6`、`UDP6`、`UnixSocket Stream/Dgram` 6種 * 使用`$sock_type | SWOOLE_SSL`可以啟用`SSL`隧道加密。啟用`SSL`后必須配置[ssl_key_file和ssl_cert_file](https://wiki.swoole.com/wiki/page/318.html) * `1.7.11`版本增加了對`Unix Socket`的支持,詳細請參見 [/wiki/page/16.html](https://wiki.swoole.com/wiki/page/16.html) * 構造函數中的參數與`swoole_server::addlistener`中是完全相同的 * 監聽端口失敗,在`1.9.16`以上版本會拋出異常,可以使用`try/catch`捕獲異常,在`1.9.16`以下版本拋出致命錯誤 * __高負載的服務器,請務必調整[Linux內核參數](https://wiki.swoole.com/wiki/page/11)__ * [ 2種Server運行模式介紹](https://wiki.swoole.com/wiki/page/353.html) 注意事項 ---- * 底層有保護機制,一個`PHP`程序內只能創建啟動一個`Server`實例 * 如果要實現多個`Server`實例的管理,父進程必須使用`exec`,不得使用`fork` 隨機可用端口 ---- swoole-1.9.6增加了隨機監聽可用端口的支持,`$port`參數可以設置為0,操作系統會隨機分配一個可用的端口,進行監聽。可以通過讀取`$server->port`得到分配到的端口號。 ```php $http = new swoole_http_server("0.0.0.0"); $http->on('request', function ($request, $response) { $response->header("Content-Type", "text/html; charset=utf-8"); $response->end("<h1>Hello Swoole. #".rand(1000, 9999)."</h1>"); }); $http->start(); ``` SYSTEMD監聽端口 ---- swoole-1.9.7增加了對`systemd socket`的支持。監聽端口由`systemd`配置指定。 #### swoole.socket ```shell [Unit] Description=Swoole Socket [Socket] ListenStream=9501 Accept=false [Install] WantedBy = sockets.target ``` #### swoole.service ```shell [Service] Type=forking PIDFile=/var/run/swoole.pid ExecStart=/usr/bin/php /var/www/swoole/server.php ExecStop=/bin/kill $MAINPID ExecReload=/bin/kill -USR1 $MAINPID [Install] WantedBy = multi-user.target ``` #### server.php ```php $http = new swoole_http_server("systemd"); $http->set([ 'daemonize' => true, 'pid_file' => '/var/run/swoole.pid', ]); $http->on('request', function ($request, $response) { $response->header("Content-Type", "text/html; charset=utf-8"); $response->end("<h1>Hello Swoole. #".rand(1000, 9999)."</h1>"); }); $http->start(); ``` #### 啟動服務 ```shell sudo systemctl enable swoole.socket sudo systemctl start swoole.socket sudo systemctl start swoole.service ```
                  <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>

                              哎呀哎呀视频在线观看