久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

    <bdo id='rVPBE'></bdo><ul id='rVPBE'></ul>

        <i id='rVPBE'><tr id='rVPBE'><dt id='rVPBE'><q id='rVPBE'><span id='rVPBE'><b id='rVPBE'><form id='rVPBE'><ins id='rVPBE'></ins><ul id='rVPBE'></ul><sub id='rVPBE'></sub></form><legend id='rVPBE'></legend><bdo id='rVPBE'><pre id='rVPBE'><center id='rVPBE'></center></pre></bdo></b><th id='rVPBE'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='rVPBE'><tfoot id='rVPBE'></tfoot><dl id='rVPBE'><fieldset id='rVPBE'></fieldset></dl></div>
      1. <small id='rVPBE'></small><noframes id='rVPBE'>

        <tfoot id='rVPBE'></tfoot>

        <legend id='rVPBE'><style id='rVPBE'><dir id='rVPBE'><q id='rVPBE'></q></dir></style></legend>

        什么更有效,為什么:每頁一個數據庫連接或每個

        whats more efficient and why: one db connection per page or one db connection per function?(什么更有效,為什么:每頁一個數據庫連接或每個函數一個數據庫連接?)

        <i id='rk9Ki'><tr id='rk9Ki'><dt id='rk9Ki'><q id='rk9Ki'><span id='rk9Ki'><b id='rk9Ki'><form id='rk9Ki'><ins id='rk9Ki'></ins><ul id='rk9Ki'></ul><sub id='rk9Ki'></sub></form><legend id='rk9Ki'></legend><bdo id='rk9Ki'><pre id='rk9Ki'><center id='rk9Ki'></center></pre></bdo></b><th id='rk9Ki'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='rk9Ki'><tfoot id='rk9Ki'></tfoot><dl id='rk9Ki'><fieldset id='rk9Ki'></fieldset></dl></div>
        • <bdo id='rk9Ki'></bdo><ul id='rk9Ki'></ul>
          • <tfoot id='rk9Ki'></tfoot>
            <legend id='rk9Ki'><style id='rk9Ki'><dir id='rk9Ki'><q id='rk9Ki'></q></dir></style></legend>

                  <tbody id='rk9Ki'></tbody>

                <small id='rk9Ki'></small><noframes id='rk9Ki'>

                  本文介紹了什么更有效,為什么:每頁一個數據庫連接或每個函數一個數據庫連接?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我正在開發一個非常受 MySQL 數據庫驅動的網站.所以我有很多疑問.

                  I am working on a website which is very MySQL DB driven. So I have a lot of queries going on.

                  在 這個話題大家建議在頁面頂部連接DB,在頁面底部斷開連接.

                  In this topic everyone recommends to connect to the DB at the top of the page, and disconnect at the bottom of the page.

                  我想知道什么更有效,或者一般來說是最佳實踐:每頁建立一個數據庫連接,還是只在需要時連接?(或者沒有一般的答案,這取決于?)

                  I am wondering what's more efficient, or generally speaking best practice: Make a single db connection per page, or only connect as needed? (Or is there no general answer, and it depends?)

                  此外,我希望找出為什么這是最佳實踐,您是從哪個角度來看場景的(例如安全性、速度……我不知道還有什么數據庫連接可能會影響?!)

                  Additionally I am looking to find out WHY is this best practice, from which point of view are you looking at the scenario (e.g. security, speed, ... I don't know what else DB connections might affect?!)

                  我相信在 這里之前已經問過這個問題 - 但不是特別針對 PHP,因此我覺得它沒有幫助.

                  I believe this question has been asked before here - but not for PHP in specific, and therefore I didn't find it helpful.

                  我目前的做法是為我編寫的每個函數連接到每個 mysqli 的數據庫,并在函數結束時斷開連接,因為對我來說它看起來更干凈.這樣,如果頁面不調用需要訪問數據庫的函數,則永遠不會打開連接.但是,可能會發生每個頁面加載最多大約 10 個連接的情況,具體取決于用戶在站點上執行的操作.現在我認為這可能是資源的公平分配.如果我理解正確,則只能始終打開 1 個 DB 連接.因此,我假設所有連接請求都將排隊.因此,如果用戶有多個、長且復雜的查詢,則該用戶不會阻止所有流量,因為在每個查詢之間,可能會處理其他短查詢.但這只是我編造的東西,我不知道它是否真的會這樣......:D

                  My current practice has been to connect to the DB per mysqli for each function I write, and disconnect at the end of the function, because it seemed cleaner to me. This way, if a page doesn't call to a function which requires DB access, there will never be a connection opened. However it may happen, that there might be up to approximately 10 connections per page load, depending on what the user does on the site. Now I thought this might be a fair distribution of resources. If I understood it correctly there can only always be 1 DB connection opened. Therefore I assume all connection requests will be queued. So if a user has multiple, long and complicated queries, this user would not hold up all traffic, because in between each of the queries, other short queries could get processed. But that's just me making stuff up, I don't know if it would really work that way... :D

                  我也知道這里的很多開發人員都喜歡使用 PDO.剛開始開發的時候選擇了mysqli,暫時沒有換的打算.我希望我的問題適用于兩個圖書館.

                  Also I know that a lot of developers around here like to use PDO. I chose to use mysqli when I started developing, and I have no plans of switching. I hope my question can be applicable to both libraries.

                  謝謝:-)

                  推薦答案

                  通常,創建數據庫連接的成本很高.這就是為什么大多數人建議創建一次連接并重復使用它直到執行停止,如果數據庫客戶端庫允許,甚至更長時間.

                  Typically database connections are expensive to create. This is why most people recommend creating the connection once and reuse it until the execution has stopped, or even longer if the database client library allows it.

                  例如,PDO 允許創建持久連接,據說這可以提高性能,因為該連接將被重復用于連續處理多個請求.來自 http://php.net/manual/en/pdo.connections.php:

                  As an example, PDO permits creating persistent connections, which supposedly enhance performance because the connection would be reused for serving several requests in a row. From http://php.net/manual/en/pdo.connections.php:

                  許多 Web 應用程序將受益于與數據庫服務器的持久連接.持久連接不會在腳本結束時關閉,而是在另一個腳本使用相同憑據請求連接時被緩存和重新使用.持久連接緩存允許您避免每次腳本需要與數據庫通信時建立新連接的開銷,從而使 Web 應用程序更快.

                  Many web applications will benefit from making persistent connections to database servers. Persistent connections are not closed at the end of the script, but are cached and re-used when another script requests a connection using the same credentials. The persistent connection cache allows you to avoid the overhead of establishing a new connection every time a script needs to talk to a database, resulting in a faster web application.

                  這篇關于什么更有效,為什么:每頁一個數據庫連接或每個函數一個數據庫連接?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  store_result() and get_result() in mysql returns false(mysql 中的 store_result() 和 get_result() 返回 false)
                  Call to undefined function mysqli_result::num_rows()(調用未定義的函數 mysqli_result::num_rows())
                  PHP Prepared Statement Problems(PHP 準備好的語句問題)
                  mysqli_fetch_array returning only one result(mysqli_fetch_array 只返回一個結果)
                  PHP MySQLi Multiple Inserts(PHP MySQLi 多次插入)
                  How do I make sure that values from MySQL keep their type in PHP?(如何確保 MySQL 中的值在 PHP 中保持其類型?)

                • <legend id='qcme1'><style id='qcme1'><dir id='qcme1'><q id='qcme1'></q></dir></style></legend>

                      • <small id='qcme1'></small><noframes id='qcme1'>

                          <bdo id='qcme1'></bdo><ul id='qcme1'></ul>

                            <tbody id='qcme1'></tbody>
                        • <i id='qcme1'><tr id='qcme1'><dt id='qcme1'><q id='qcme1'><span id='qcme1'><b id='qcme1'><form id='qcme1'><ins id='qcme1'></ins><ul id='qcme1'></ul><sub id='qcme1'></sub></form><legend id='qcme1'></legend><bdo id='qcme1'><pre id='qcme1'><center id='qcme1'></center></pre></bdo></b><th id='qcme1'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='qcme1'><tfoot id='qcme1'></tfoot><dl id='qcme1'><fieldset id='qcme1'></fieldset></dl></div>
                          <tfoot id='qcme1'></tfoot>
                            主站蜘蛛池模板: 国产激情在线 | 国产高潮好爽受不了了夜夜做 | 亚洲福利网 | 日韩视频 中文字幕 | 五月天激情电影 | 中文字幕不卡在线88 | 国产网站在线 | 国产午夜精品福利 | 久久精品亚洲 | 日日干综合 | 日韩三 | 中文字幕一区二区三区四区五区 | 日韩精品免费视频 | 国产免费视频 | 亚洲精品日韩一区二区电影 | 国产电影精品久久 | 欧美色综合| 日韩a视频 | 日韩不卡在线观看 | 久久久免费| 国产精品一区在线 | 婷婷久久一区 | 在线观看中文字幕视频 | 精品视频一区二区三区 | 大乳boobs巨大吃奶挤奶 | 欧美日韩国产精品 | 亚洲精品久久久久久国产精华液 | 亚洲欧美一区二区在线观看 | 精品国产视频 | 国产欧美综合在线 | 亚洲成av人影片在线观看 | 欧美精品一区二区三区四区五区 | 一道本在线 | 一区二区三区在线播放 | 在线观看av网站永久 | www国产亚洲精品久久网站 | 欧美精品久久久 | 黄a在线观看 | 91久久精品日日躁夜夜躁国产 | 久久久青草婷婷精品综合日韩 | 国产在线精品一区二区三区 |