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

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                ##方案三:定時讀取緩存方式開發首頁接口 流程:http請求 -> 緩存(crontab從數據庫獲取緩存) -> 封裝并返回數據 學習要點: 1. 掌握如何編寫定時腳本程序 2. 理解服務器如何提前準備數據 ![](https://box.kancloud.cn/c289d209a55ec14e495212d69f0d68c9_602x330.png) *增加crontab執行文件:var/www/app/cron.php* ``` // 讓crontab定時執行的腳本程序 */5 * * * * /usr/bin/php /var/www/app/cron.php // 獲取user表中6條數據 require_once('./db.php'); require_once('./file.php'); $sql = "select * from mk_user where score != 0 order by id desc"; try { $connect = Db::getInstance()->connect(); } catch(Exception $e) { // $e->getMessage(); // 鏈接失敗,在日志文件里記錄失敗的記錄 file_put_contents('./logs/' . date('y-m-d') . '.txt', $e->getMessage()); return; } $result = mysql_query($sql, $connect); $users = array(); while ($user = mysql_fetch_assoc($result)) { $users[] = $user; } $file = new File(); if($users) { // 有數據的話,把數據寫到緩存文件里 $file->cacheData('index_cron_cache', $users); } else { file_put_contents('./logs/' . date('y-m-d') . '.txt', "沒有相關數據"); } return; ``` *上面的crontab沒5分鐘執行一次,當有數據時,在list.php文件開頭能夠查詢到數據:var/www/app/list.php* ``` require_once('./response.php'); require_once('./file.php'); // 增加下面對緩存進行查詢 $file = new File(); $data = $file->cacheData('index_cron_cache'); if ($data) { return Response::show(200, '首頁數據獲取成功', $data); } else { return Response::show(400, '首頁數據獲取失敗', $data); } require_once('./db.php'); ```
                  <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>

                              哎呀哎呀视频在线观看