使用與跑的WordPress Blog的PHP-MySQL堅持連接
默認情況下當連接到MySQL數據庫時,根據PHP寫電影腳本的WordPress weblog將使用非堅持連接。 即,一旦網頁大廈完成, WordPress將觸發PHP引起與MySQL服務器的新的連接為每個動態頁請求和隨後關閉數據庫連接。 MySQL連接反覆開頭和closing在WEB主機導致天花板并且用盡珍貴的CPU、記憶和系統資源。
使用堅持連接連接到MySQL數據庫服務器總不是一個好選擇。 每連接佔去資源,包括記憶,緩衝、桌或螺紋貯藏所內部在MySQL和插口,打開文件或者IO活動在OS水平。 因而,當打開很多堅持連接,但沒有被關閉時,在交易完成之後,資源在系統也許漏和貶低網絡服務器表現,或者在最壞,起因HTTP失敗。 此外,如果堅持連接失去作用,不活潑或變得停止活動或不再在使用,它沒有被終止,并且MySQL服務器在my.cnf配置文件只將關閉它發布連接佔領的資源在大約28800秒(8個小時)以後默認情況下,除非改變暫停參量。 如果應用不適當地處理堅持連接,這少量因素也許帶來麻煩例如MySQL拒绝新的DB連接或慢服務器。 因而,如果您不是經驗Web站點管理員,不要試圖改變Wordpress使用堅持連接。
然而,為有繁忙和大blog的bloggers和飾面限制在升級WEB主機系統規範,和不要想要使用靜態頁貯藏插入式例如WP貯藏所,堅持連接是調整和優選網絡服務器的一個可利用的選擇看網頁服務是否可以是更加快速的。 當劇本的施行結束時,堅持連接一次允許連接是開放的和不會是閉合的。 反而,鏈接在水池被保留,并且保持開放為未來的用途。 因此,使用堅持連接將消滅開頭和closing的過程連接。 這將間接地減少MySQL連接相關的服務器天花板例如認證建立連接只一次是需要的地方,保存額外用於的網絡信息流通量和資源處理額外連接。 在旁邊,可能有一些連接水平貯藏所,需要為適當的表現填滿和潛在地減少連接的數量與數據庫的。
默認情況下, WordPress使用在每頁建立一個新的數據庫連接的mysql_connect ()作用。 The persistent connection feature will require mysql_pconnect() function which uses the exact same API, but has built-in connection pooling to keep connections alive between requests. So to switch to use persistent connection to run WordPress, the mysql_connect() function has to be replaced with mysql_pconnect().
To enable and use persistent connections with WordPress, simply login to your web host with SSH (or insecure Telnet), and change to the webroot home directory where WordPress blog is installed. Then change directory into wp-includes directory. Inside the wp-includes directory, there is wp-db.php file. Use any text editor such as vi to edit wp-db.php. Search or locate the function of mysql_connect (or @mysql_connect). There is only one instance of mysql_connect. Just change the mysql_connect to mysql_pconnect, then save and exit the wp-db.php. WordPress and PHP (as long as you don’t turn off the mysql.allow_persistent in PHP.INI) will immediately use persistent connections to connect to MySQL database. It’s worth to try out which setting is best for your environment.
IMPORTANT: This is a machine translated page which is provided "as is" without warranty. Machine translation may be difficult to understand. Please refer to original English article whenever possible.
Share and contribute or get technical support and help at My Digital Life Forums.
Related Articles
- How to Move WordPress Blog to New Domain or Location
- How to Customize, Modify or Change WordPress Database Connection Error Page
- Integrate WordPress including Comments with bbPress Forum using bbSync
- StatTraq - Wordpress Plugin for Site Statistic and Traffic Counter
- 3 Column Relaxation WordPress Theme comments-paged.php for Paged-Comments WordPress Plugin
- How to Delete Existing WordPress Post Revisions Stored/Saved
- Run WordPress at Top Fast Speed by Putting Objects and Variables into XCache or eAccelerator Cache Memory (Plugin)
- How to Change the Frequency or Interval WordPress Auto Saves An Editing Post or Page
- WordPress MySQL SQL Query Error in WPDB Class
- Technorati Incoming Links Plugin for WordPress

































September 27th, 2007 22:14
This seemed to do the trick for. Thanks so much for the info!