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

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                # 4.6 配置 配置是框架的重要組成部分,MSF框架的配置組件采用了第三方的[hassankhan/config](https://github.com/hassankhan/config),它支持多種配置書寫的文件格式如:PHP,INI,XML,JSON,YAML,可以滿足大部分的配置需求。但是建議采用PHP數組文件來配置我們的服務。 ## PHP配置數組文件 配置采用PHP數組的形式進行書寫,每個配置文件的最后一行都需要返回,即`return $config`,如: ```php <?php /** * MongoDb配置文件 * * @author camera360_server@camera360.com * @copyright Chengdu pinguo Technology Co.,Ltd. */ $config['mongodb']['test']['server'] = 'mongodb://192.168.1.106:27017'; $config['mongodb']['test']['options'] = ['connect' => true]; $config['mongodb']['test']['driverOptions'] = []; return $config; ```` ## 配置目錄 在應用程序的主目錄中有`config`目錄,是用來存放所有配置文件,配置目錄的參考結構: ``` ├── config // 配置目錄 │?? ├── check.php // 代碼檢查配置 │?? ├── server.php // 主配置文件(server服務相關) │?? ├── constant.php // 業務常量定義文件 │?? ├── log.php // 全局日志配置 │?? ├── http.php // HTTP服務配置 │?? ├── params.php // 全局業務配置(和運行環境無關) │?? ├── dev // 研發聯調環境特殊配置目錄 │?? ├── docker // docker環境特殊配置目錄 │?? ├── product // 生產環境特殊配置目錄 │?? ├── qa // QA環境特殊配置目錄 ``` 對于各個環境的差異配置,單獨存在在不同的目錄中,如: `config/docker` 存放Docker環境配置 `config/dev` 存放研發聯調環境配置 `config/qa` 存放QA環境配置 `product` 存放生產環境配置 ## 主配置文件 是配置服務實例的大部分配置,包括Http Server的參數配置,服務器進程pid文件目錄,服務進程名稱,服務器worker、Task、reactor數量等等。 ### 主配置重要選項說明 #### $config['server'] - $config['server']['process_title'] server服務進程標題前綴 - $config['server']['runtime_path'] server服務運行時目錄 - $config['server']['pid_path'] server服務運行時pid目錄 - $config['server']['route_tool'] server服務路由分發請求的類名,首先查找app\Route目錄,再查到php-msf\src\Route目錄,默認為`NormalRoute` #### $config['server']['set'] - $config['server']['set']['reactor_num'] swoole server的reactor數量,更多請參考[reactor_num](https://wiki.swoole.com/wiki/page/281.html) - $config['server']['set']['worker_num'] swoole server的worker數量,更多請參考[worker_num](https://wiki.swoole.com/wiki/page/275.html) - $config['server']['set']['backlog'] swoole server的backlog隊列長度,更多請參考[backlog](https://wiki.swoole.com/wiki/page/279.html) - $config['server']['set']['dispatch_mode'] swoole server的數據包分發策略,對于http服務器推薦設置為1,更多請參考[dispatch_mode](https://wiki.swoole.com/wiki/page/277.html) - $config['server']['set']['task_worker_num'] swoole server的task worker數量,更多請參考[task_worker_num](https://wiki.swoole.com/wiki/page/276.html) swoole server的其他配置項,具體參考:[配置選項](https://wiki.swoole.com/wiki/page/274.html) #### $config['config_manage_enable'] 是否啟動配置進程,設置為true或者false #### $config['auto_reload_enable'] 是否開啟自動檢測文件更新,并重啟服務,在開發環境建議設置為true,生產環境設置為false #### $config['user_timer_enable'] 是否開啟自定義業務Timer進程,為業務需求而定,主要用于一些定時業務,設置為true或者false #### $config['http_server'] Http服務器相關配置,主要有以下幾個重要子配置項 - $config['http_server']['port'] Http服務器監聽的端口 - $config['http_server']['socket'] Http服務器監聽的地址 #### $config['http'] - $config['http']['domain'] 使用Http服務器時,綁定的域名列表 - $config['http']['domain']['localhost'] 使用Http服務器時,綁定一個localhost的域名 - $config['http']['domain']['localhost']['root'] 使用Http服務器時,綁定了一個localhost的域名,并且域名對應的根目錄為此配置項的值,需要特別注意的是,一旦配置了root,那該目錄下所有文件就可以被用戶訪問到 - $config['http']['domain']['localhost']['index'] 使用Http服務器時,綁定了一個localhost的域名,并且域名對應的索引文件此配置項的值 - $config['http']['default_method'] 使用Http服務器時,Controller的默認方法名,在路由請求時使用 ## 日志配置 ```php <?php /** * 日志配置文件 * * @author camera360_server@camera360.com * @copyright Chengdu pinguo Technology Co.,Ltd. */ $config['server']['log'] = [ 'handlers' => [ 'application' => [ 'levelList' => [ \PG\Log\PGLog::EMERGENCY, \PG\Log\PGLog::ALERT, \PG\Log\PGLog::CRITICAL, \PG\Log\PGLog::ERROR, \PG\Log\PGLog::WARNING ], 'dateFormat' => "Y/m/d H:i:s", 'format' => "%datetime% [%level_name%] [%channel%] [logid:%logId%] %message%\n", 'stream' => RUNTIME_DIR . '/application.log', 'buffer' => 0, ], 'notice' => [ 'levelList' => [ \PG\Log\PGLog::NOTICE, \PG\Log\PGLog::INFO, \PG\Log\PGLog::DEBUG ], 'dateFormat' => "Y/m/d H:i:s", 'format' => "%datetime% [%level_name%] [%channel%] [logid:%logId%] %message%\n", 'stream' => RUNTIME_DIR . '/notice.log', 'buffer' => 0, ] ] ]; return $config; ``` 更新配置示例請參考示例項目[php-msf-demo/config](https://github.com/pinguo/php-msf-demo/blob/master/config/log.php) ## 使用配置 在任何地方都可以通過`getInstance()->config`來訪問讀取配置,另外在繼承`\PG\MSF\Base\Core`類的子類(比如Controller/Model等等)都可以通過`$this->getConfig()`來獲取配置對象,訪問配置項的代碼如: [php-msf/config/params.php](https://github.com/pinguo/php-msf/pinguo/config/params.php) ```php <?php /** * 業務參數 * * @author camera360_server@camera360.com * @copyright Chengdu pinguo Technology Co.,Ltd. */ $config['params']['mock_ids'] = [ '581af00d4b58d59d22e8d7a6', '581198754b58d54465ef4cad', '580c7fa44b58d53f43e21c43', '57ef6aec4b58d50d24e21a2a', '57ee28ed4b58d52f24e21969', '57eb6a484b58d50e3d078076', '57e23b444b58d52f1e6689fc', '57dfc9fc4b58d5581e668918', '57de06b74b58d5471e66882f', '57d8b78f4b58d5311e6686d5', ]; return $config; ``` ```php getInstance()->config->get('params.mock_ids', []) ``` get()方法的第一個參數為key名稱,對于多維數組的配置,采用點分隔;第二個參數為配置選項默認值,即沒有讀取到配置時的默認配置。
                  <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>

                              哎呀哎呀视频在线观看