Using PHP-MySQL Persistent Connections to Run WordPress Blog Sử dụng PHP-MySQL Persistent Connections để Khởi WordPress Blog
When connecting to MySQL database, WordPress weblog based on PHP scripting will use non-persistent connection by default. Khi kết nối với cơ sở dữ liệu MySQL, WordPress weblog dựa trên PHP scripting sẽ sử dụng không cố kết nối theo mặc định. That is, WordPress will trigger PHP to generate a new connection to MySQL server for each dynamic page request, and subsequently close the database connection once the web page building is completed. Đó là, WordPress sẽ kích hoạt PHP để tạo ra một kết nối mới tới máy chủ MySQL cho từng yêu cầu trang năng động, và sau đó đóng kết nối cơ sở dữ liệu một khi xây dựng trang web hoàn tất. Repetitive opening and closing of MySQL connections causes overheads and uses up precious CPU, memory and system resources on the web host. Lặp đi lặp lại khai mạc và bế mạc của các kết nối MySQL overheads nguyên nhân và sử dụng hết quý CPU, bộ nhớ và tài nguyên hệ thống trên máy chủ web.
Using persistent connection to connect to MySQL database server is not always a good option. Sử dụng kết nối liên tục để kết nối với máy chủ cơ sở dữ liệu MySQL không phải luôn luôn là một lựa chọn tốt. Each connections takes up resources, including memory, buffers, table or thread caches internally in MySQL and sockets, open files or IO activity at OS level. Mỗi kết nối chiếm tài nguyên, bao gồm cả bộ nhớ, bộ đệm, bảng hoặc thread lưu trữ nội bộ trong MySQL và ổ cắm, tập mở hoặc IO hoạt động ở cấp hệ điều hành. Thus when a lot of persistent connections are opened but not closed after transactions are completed, the resources on system may drain up and degrade performance of web server, or in worst case, cause HTTP failure. Vì vậy, khi rất nhiều các kết nối liên tục được mở nhưng không phải đóng cửa sau khi giao dịch được hoàn thành, các nguồn tài nguyên trên hệ thống có thể cống lên và làm suy giảm hiệu suất của máy chủ web, hoặc trong trường hợp xấu nhất, nguyên nhân thất bại HTTP. Furthermore, if a persistent connection is stalled, inactive or became defunct or no longer in used, it is not terminated, and MySQL server will only close it to release the resource occupied by the connection after about 28800 seconds (8 hours) by default unless changed the timeout parameters in my.cnf configuration files. Hơn nữa, nếu một kết nối liên tục được ngừng lại, không hoạt động hoặc trở nên không còn tồn tại hoặc không còn được sử dụng, nó không phải là chấm dứt, và máy chủ MySQL sẽ chỉ đóng nó để giải phóng tài nguyên chiếm đóng các kết nối sau khoảng 28.800 giây (8 giờ) theo mặc định, trừ khi thay đổi các tham số timeout trong file cấu hình my.cnf. This few factors may bring troubles such as MySQL refusing new DB connections or slow server if the applications do not properly handle persistent connections. Vài yếu tố này có thể mang lại rắc rối như MySQL từ chối kết nối DB mới hoặc máy chủ chậm nếu các ứng dụng không đúng cách xử lý các kết nối liên tục. Thus if you're not experience webmasters, please do not attempt to change Wordpress to use persistent connections. Vì vậy nếu bạn không có kinh nghiệm quản trị web, xin đừng cố gắng thay đổi Wordpress để sử dụng các kết nối liên tục.
However, for bloggers who have busy and large blog, and facing constraints in upgrading web host system specifications, and do not want to use static page caching plugin such as WP-Cache, persistent connection is a available option to tune and optimize the web server to see if the webpage serving can be faster. Tuy nhiên, đối với các blogger có blog bận rộn và lớn, và phải đối mặt với những hạn chế trong việc nâng cấp thông số kỹ thuật hệ thống máy chủ lưu trữ web, và không muốn sử dụng trang tĩnh caching plugin như WP-Cache, kết nối liên tục là một lựa chọn có sẵn để điều chỉnh và tối ưu hóa các máy chủ web để xem các trang web có thể được phục vụ nhanh hơn. Persistent connection allows connection to be open once and will not be closed when the execution of the script ends. Liên tục kết nối cho phép kết nối được mở một lần và sẽ không được đóng cửa khi thực hiện lệnh kết thúc. Instead, the link is kept in pool and will remain open for future use. Thay vào đó, liên kết được giữ trong hồ bơi và sẽ vẫn được mở để sử dụng trong tương lai. Thus, using persistent connections will eliminate the process of opening and closing the connection. Vì thế, bằng cách sử dụng các kết nối liên tục sẽ loại bỏ quá trình đóng kết nối. This will indirectly reduce MySQL connection related server overheads such as authentication to establish connection where only once is needed, saving extra network traffic, and resources used to handle extra connection. Điều này sẽ làm giảm gián tiếp kết nối máy chủ MySQL overheads liên quan như: xác thực để thiết lập kết nối mà chỉ một lần là cần thiết, tiết kiệm lưu lượng mạng thêm, và các nguồn lực được sử dụng để xử lý kết nối thêm. Beside, there could be some connection level caches, which need to be filled up for proper performance, and potentially reduce the number of connections to the database. Bên cạnh đó, có thể được một số kết nối cache cấp, mà cần phải được điền ký hiệu thích hợp, và có khả năng làm giảm số lượng kết nối đến cơ sở dữ liệu.
By default, WordPress is using mysql_connect() function that establishes a new database connection on every page. Theo mặc định, WordPress đang sử dụng mysql_connect () có chức năng thiết lập một kết nối cơ sở dữ liệu mới trên mỗi trang. 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. Tính năng kết nối liên tục sẽ đòi hỏi mysql_pconnect () có chức năng sử dụng cùng một API chính xác, nhưng đã được xây dựng trong kết nối tổng hợp để giữ cho các kết nối sống giữa yêu cầu. So to switch to use persistent connection to run WordPress, the mysql_connect() function has to be replaced with mysql_pconnect(). Vì vậy, để chuyển sang sử dụng kết nối liên tục để chạy WordPress, các mysql_connect () chức năng đã được thay thế bằng 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. Để kích hoạt và sử dụng các kết nối liên tục với WordPress, chỉ cần đăng nhập vào máy chủ web của bạn với SSH (hoặc không an toàn Telnet), và để thay đổi thư mục chính webroot nơi blog được cài đặt. Then change directory into wp-includes directory. Sau đó thay đổi thư mục thành wp-bao gồm các thư mục. Inside the wp-includes directory, there is wp-db.php file. Bên trong wp-bao gồm các thư mục, có wp-db.php file. Use any text editor such as vi to edit wp-db.php. Sử dụng bất kỳ trình soạn thảo văn bản như vi để chỉnh sửa wp-db.php. Search or locate the function of mysql_connect (or @mysql_connect ). Tìm kiếm hoặc định vị chức năng của mysql_connect (hoặc @ mysql_connect). There is only one instance of mysql_connect. Chỉ có một ví dụ của mysql_connect. Just change the mysql_connect to mysql_pconnect , then save and exit the wp-db.php. Chỉ cần thay đổi mysql_connect để mysql_pconnect, sau đó lưu và thoát khỏi 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. WordPress và PHP (miễn là bạn không tắt mysql.allow_persistent trong php.ini) ngay lập tức sẽ sử dụng các kết nối liên tục để kết nối với cơ sở dữ liệu MySQL. It's worth to try out which setting is best for your environment. It's trị giá để thử xem cái nào thiết lập là tốt nhất cho môi trường của bạn.
IMPORTANT : The page is machine translated and provided "as is" without warranty. Quan trọng: Sửa là máy dịch và cung cấp "như là" không có bảo hành. Machine translation may be difficult to understand. Máy dịch thuật có thể khó hiểu. Please refer to Vui lòng tham khảo original English article bản gốc tiếng Anh bài viết whenever possible. bất cứ khi nào có thể.
Related Articles Bài viết liên quan
- How to Move WordPress Blog to New Domain or Location Làm thế nào để Move WordPress Blog đến New Domain hay Địa điểm
- WordPress MySQL SQL Query Error in WPDB Class WordPress MySQL vấn SQL Error in WPDB Class
- Moderate WordPress Blog Comments Via Moderator with Desktop Client Trung bình WordPress Blog bình Via Người điều hành với máy tính để bàn Khách hàng
- How to Customize, Modify or Change WordPress Database Connection Error Page Làm thế nào để Customize, Chỉnh sửa hoặc thay đổi kết nối WordPress Cơ sở dữ liệu Lỗi Trang
- Replace Google Blog Search with Technorati for Incoming Links in Dashboard of WordPress Thay thế Google Blog Search với Technorati cho Incoming kết trong Bảng điều khiển của WordPress
- WLWManifest Disabler Plugin to Remove XLM Link in WordPress Blog Header WLWManifest Disabler Plugin để Hủy bỏ XLM kết trong WordPress Blog Header
- AdSense and Display Banner Ads Rotation in WordPress Blog or Websites AdSense và xoay Hiển thị Banner Quảng cáo trong WordPress Blog hoặc Website
- Integrate and Display Google AdSense for Search and Co-Op Custom Search Engine Results in WordPress Blog Page Template Tích hợp và hiển thị Google AdSense cho Tìm kiếm và Co-Op cụ Tìm kiếm Tuỳ Kết quả trong WordPress Blog Trang Template
- Change and Reset MySQL root Password Thay đổi và Thiết lập lại mật khẩu root MySQL
- Paginating or Split WordPress Post or Page with NextPage in WordPress Not Working Paginating hoặc Split WordPress Đăng hoặc Trang với NextPage trong WordPress Không phải làm việc










































September 23rd, 2009 14:37 Ngày 23 Tháng Chín 2009 14:37
Thanks a lot.I really do not know about the function mysql_pconnect().Will going to implement it practically soon. Thanks a lot.I thực sự không biết về chức năng mysql_pconnect (). Sẽ đi thực tế để thực hiện nó ngay.
November 22nd, 2008 10:20 22 tháng 11 năm 2008 10:20
THANK YOU SO MUCH! THANK YOU SO MUCH!
WordPress is running so much faster now! WordPress là chạy nhanh hơn rất nhiều bây giờ!
I am running all on Windows Server 2008 with: Tôi đang chạy cả trên Windows Server 2008 với:
- MySQL Server v5.0 x64 (on dedicated server) - MySQL Server v5.0 x64 (trên máy chủ chuyên dụng)
- IIS7 with FastCGI z32 (on dedicated server) - IIS7 với FastCGI z32 (trên máy chủ chuyên dụng)
Regards, Kính trọng,
raja raja
September 27th, 2007 22:14 Ngày 27 tháng 9 năm 2007 22:14
This seemed to do the trick for. Điều này dường như làm cho lừa. Thanks so much for the info! Thanks so much for the info!