<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] ## 訪問 url 在 `httpController` 目錄中,如何直接寫 index.php 類,則只需要訪問`ip:port/`即可 如何寫出目錄格式,則安裝格式訪問,如`api/index.php` 訪問 `ip:port/api/` ## 使用`Singleton`創建一個單例 引入`use \EasySwoole\Component\Singleton;`創建一個 redis 單例 ``` namespace App\lib; class Redis{ // 重點需要引入提供的單例 trait use \EasySwoole\Component\Singleton; public $redis; private function __construct(){ if(!extension_loaded("redis")){ throw new \Exception("redis.io 文件不存在"); } try{ $this->redis = new \Redis(); $result = $this->redis->connect("127.0.0.1", 6379, 3); } catch (\Exception $e){ throw new \Exception("redis 服務器異常"); } if ($result===false){ throw new \Exception("redis connect is failed"); } } public function get($key){ if (empty($key)) { return ''; } return $this->redis->get($key); } public function set($key, $value){ return $this->redis->set($key, $value); } } ``` 使用 ``` $redis = \App\lib\Redis::getInstance(); $redis->set("a", "b"); $redis->get("a"); ``` ## 自動引入配置文件(^3.0) 配置文件 ``` /Config ├── Mysql.php └── redis.php ``` EasySwooleEvent.php ``` //在initialize 函數下編寫一下代碼 $configPath = EASYSWOOLE_ROOT . "/Config/"; $configs = []; $handler = opendir($configPath); while (($filename = readdir($handler)) !== false) {//務必使用!==,防止目錄下出現類似文件名“0”等情況 if ($filename != "." && $filename != "..") { $path = $configPath . $filename; $configs[basename($filename, '.php')] = include_once $path; } } foreach ($configs as $k => $v) { \EasySwoole\EasySwoole\Config::getInstance()->setConf(strtoupper($k), $v); } //使用 \EasySwoole\EasySwoole\Config::getInstance()->getConf("MYSQL"); ``` ## 文件上傳 2.0+ ``` $request = $this->request(); $file = $request->getUploadedFile("file"); $flag = $file->moveTo("a.mp4"); $file->getStream(); // 獲取文件Stream $file->moveTo('Public/Ez.gif'); // 移動文件(file_put_contents實行) $file->getSize(); // 獲取文件大小 $file->getErroe(); // 獲取錯誤序號 $file>getClientFilename(); // 獲取客戶端文件名 $file->getClientMediaType(); // 獲取客戶端媒體類型 ``` ## `request()->getBody()->__toString()`替換`file_get_contents('php://input')` ## 處理請求前 ``` function onRequest(?string $action): ?bool { if (parent::onRequest($action)) { //判斷是否登錄 if (1/*偽代碼*/) { $this->writeJson(Status::CODE_UNAUTHORIZED, '', '登入已過期'); return false; } return true; } return false; } ``` ## 跨域處理 ``` public static function onRequest(Request $request, Response $response): bool { // TODO: Implement onRequest() method. $response->withHeader('Access-Control-Allow-Origin', '*'); $response->withHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS'); $response->withHeader('Access-Control-Allow-Credentials', 'true'); $response->withHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization, X-Requested-With'); if ($request->getMethod() === 'OPTIONS') { $response->withStatus(Status::CODE_OK); return false; } return true; } ```
                  <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>

                              哎呀哎呀视频在线观看