A-A+

使用PHP – MySQL的持久连接运行的WordPress博客

2008年11月29日 WordPress 暂无评论 阅读 1 次

When connecting to MySQL database, WordPress weblog based on PHP scripting will use non-persistent connection by default.当连接到MySQL数据库,在WordPress博客基于PHP脚本将使用非持久连接默认情况下。 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.这是,在WordPress会触发PHP中生成一个新的连接到MySQL服务器为每个动态页面的请求,并随后关闭数据库连接,一旦网页建设,是完成。 Repetitive opening and closing of MySQL connections causes overheads and uses up precious CPU, memory and system resources on the web host.重复的开幕和闭幕的MySQL连接的原因和间接利用了宝贵的CPU ,内存和系统资源在网上东道国。

Using persistent connection to connect to MySQL database server is not always a good option.使用持久性连接来连接到MySQL数据库服务器并不总是一个好的选择。 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.每个连接占用的资源,包括内存,缓冲器,表或线程缓存国内在MySQL和插座,打开文件或印务局的活动在操作系统的水平。 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.因此,当大量的持久连接开放的而不是封闭后,交易完成后,资源,系统可能会流失和降解性能的Web服务器,或在最坏的情况下,事业的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.此外,如果持续的连线是停滞不前,成为无效或停业或不再在使用,这是没有终止, MySQL服务器将只将它关闭,以释放所占用资源的连接后约二八八〇 〇秒( 8小时)默认情况下,除非改变了超时参数的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.这几个因素可能带来的麻烦,如MySQL的拒绝新分贝的关系,或缓慢,服务器,如果申请不妥善处理持久连接。 Thus if you’re not experience webmasters, please do not attempt to change Wordpress to use persistent connections.因此,如果您没有经验的网站管理员,请不要试图改变WordPress所使用的持久连接。

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.然而,对于博客谁也忙,博客规模较大,面临的制约因素,在提升Web主机的系统规格,以及不想使用静态网页缓存插件,如可湿性粉剂-快取记忆体,持续的连线是一个可行的选择,以调整和优化Web服务器看看网页服务,可以更快。 Persistent connection allows connection to be open once and will not be closed when the execution of the script ends.持久连接允许连接到开放后并不会关闭时,执行该脚本结束。 Instead, the link is kept in pool and will remain open for future use.反之,链接是存放在游泳池和将继续开放,供今后使用。 Thus, using persistent connections will eliminate the process of opening and closing the connection.因此,使用持久连接,将消除的过程中打开和关闭连接。 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.这将间接地减少MySQL连接相关的服务器,如间接验证建立连接的地方只有一次是需要,节省额外的网络流量,以及所用的资源来处理额外的连接。 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.旁边的,可能会有一些方面的水平高速缓存,需要加以填补了适当的表现,以及潜在的数目减少连接到数据库。

By default, WordPress is using mysql_connect() function that establishes a new database connection on every page.默认情况下,在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.持续连接功能将需要mysql_pconnect ( )函数使用完全相同的空气污染指数,但已内置在连接池,以保持连接活着之间的请求。 So to switch to use persistent connection to run WordPress, the mysql_connect() function has to be replaced with mysql_pconnect().因此,切换到使用持久连接运行的WordPress , mysql_connect ( )函数已被取代,与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.启用和使用的持久连接与在WordPress ,只需登录到您的Web主机的SSH (或不安全的Telnet ) ,并更改到了Webroot家所在的目录WordPress所博客安装。 Then change directory into wp-includes directory.然后将目录更改到可湿性粉剂-包括目录。 Inside the wp-includes directory, there is wp-db.php file.内可湿性粉剂-包括目录,有可湿性粉剂- db.php文件。 Use any text editor such as vi to edit wp-db.php.使用任何文本编辑器,如六编辑可湿性粉剂- db.php 。 Search or locate the function of mysql_connect (or @mysql_connect ).搜索或找到的功能, mysql_connect (或@ mysql_connect ) 。 There is only one instance of mysql_connect.只存在一个实例mysql_connect 。 Just change the mysql_connect to mysql_pconnect , then save and exit the wp-db.php.只是改变mysql_connect以mysql_pconnect ,然后保存并退出可湿性粉剂- 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和PHP (只要你不关闭mysql.allow_persistent在php.ini )将立即使用持久连接连接到MySQL数据库。 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.只要有可能。

给我留言

Copyright © 浩然东方 保留所有权利.   Theme  Ality 07032740

用户登录