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


3 Responses to “Using PHP-MySQL Persistent Connections to Run WordPress Blog” 3 Responses to "Sử dụng PHP-MySQL Persistent Connections để Khởi WordPress Blog"

  1. Out Ngoài
    September 23rd, 2009 14:37 Ngày 23 Tháng Chín 2009 14:37
    3 3

    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.

  2. raja raja
    November 22nd, 2008 10:20 22 tháng 11 năm 2008 10:20
    2 2

    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

  3. Edward Edward
    September 27th, 2007 22:14 Ngày 27 tháng 9 năm 2007 22:14
    1 1

    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!

Leave a Reply Để lại một trả lời

You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> Bạn có thể sử dụng các thẻ: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime = ""> <em> <i> <q <strike> <strong>

Subscribe to comments feature has been disabled. Thuê bao với ý kiến đều đã bị vô hiệu hoá. To receive notification of latest comments posted, subscribe to Để nhận được thông báo mới nhất đăng ý kiến, đăng ký với My Digital Life Comments RSS feed My Digital Life kiến RSS feed or hoặc register to receive đăng ký để nhận được new comments in daily email digest. Các ý kiến mới trong email tiêu hàng ngày.
Custom Search

New Articles Bài viết mới

Incoming Search Terms for the Article Tìm đến các Điều khoản Điều

mysql persistent connection mysql liên tục kết nối - -- MySQL persistent connections MySQL tục kết nối - -- wordpress persistent connections wordpress kết nối liên tục - -- php mysql persistent connection php mysql liên tục kết nối - -- php mysql wordpress php mysql wordpress - -- wordpress mysql connection wordpress kết nối mysql - -- wordpress persistent connection wordpress kết nối liên tục - -- php persistent connections php liên tục kết nối - -- mysql persistent mysql dai dẳng - -- php mysql persistent connections php mysql liên tục kết nối - -- php mysql persistent php mysql dai dẳng - -- persistent connection mysql liên tục kết nối mysql - -- WORDPRESS PHP MYSQL WordPress PHP MYSQL - -- persistent connections mysql kết nối liên tục mysql - -- wordpress mysql_connect wordpress mysql_connect - -- wordpress mysql timeout wordpress timeout mysql - -- mysql_pconnect wordpress mysql_pconnect wordpress - -- php persistent connection php liên tục kết nối - -- Reduce or eliminate persistent connections to reduce connection usage Giảm hoặc loại bỏ các kết nối liên tục để giảm bớt việc sử dụng kết nối - -- mysql persistent links mysql dai dẳng liên kết - -- wordpress mysql_pconnect wordpress mysql_pconnect - -- wordpress mysql persistent connection wordpress mysql kết nối liên tục - -- persistent connection liên tục kết nối - -- mysql connections mysql kết nối - -- wordpress mysql connect wordpress mysql kết nối - -- persistent connections wordpress kết nối liên tục wordpress - -- mysql persistent connection performance mysql liên tục kết nối hiệu quả - -- persistent mysql dai dẳng mysql - -- php persistent mysql connection php mysql liên tục kết nối - -- mysql php persistent connection mysql php liên tục kết nối - -- wordpress mysql persistent connections wordpress mysql kết nối liên tục - -- persistent connection mysql php liên tục kết nối mysql php - -- wordpress connection pool wordpress kết nối bơi - -- wordpress db connection wordpress db kết nối - -- mysql_connect wordpress mysql_connect wordpress - -- wordpress connection pooling wordpress kết nối tổng hợp - -- php persistent mysql php dai dẳng mysql - -- mysql allow persistent mysql cho phép liên tục - -- persistent connection php liên tục kết nối php - -- persistent mysql connection dai dẳng mysql kết nối - -- wordpress persistent mysql wordpress mysql dai dẳng - -- mysql persistent connection php mysql liên tục kết nối php - -- mysql connect persistent mysql kết nối liên tục - -- wordpress database connection pool wordpress kết nối cơ sở dữ liệu hồ bơi - -- connection mysql php kết nối mysql php - -- php mysql connection pooling php mysql kết nối tổng hợp - -- wordpress persistent db wordpress db dai dẳng - -- Wordpress connection to MySQL Wordpress kết nối với MySQL - -- mysql.allow_persistent wordpress mysql.allow_persistent wordpress - -- php mysql persistant connection php mysql liên tục kết nối - --