不关闭推进连接的性能影响 [英] Performance impact of not closing propel connection

查看:94
本文介绍了不关闭推进连接的性能影响的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个项目中使用的是symfony 1.4 / propel 1.4,该项目是由其他开发人员先前开发的。在该项目上,使用以下代码进行推进连接

  $ con = Propel :: getConnection(UsersPeer :: DATABASE_NAME,Propel :: CONNECTION_WRITE); 

但是它永远不会使用



<$关闭连接p $ p> Propel :: close();

我刚刚搜索到有1500多个这样的事件导致连接断开&我猜它们都不是关闭连接。



我知道关闭连接始终是一种很好的做法,但在目前情况下,看来我无法将所有这些都固定为固定所有事件肯定会花费很多时间,可能是一整天。所以现在我很困惑是否应该解决此问题。如果让我这样,会对性能产生影响吗?



编辑:仅供参考



此问题的第二部分使用关闭数据库php中的连接

解决方案

如果有的话,显式关闭连接可能会损害性能。在合理的假设下一个请求将使用相同的凭据的情况下,PDO通常会缓存从一个请求到下一个请求的连接。



编辑:阅读 docs ,在我看来,无论是否尝试关闭PDO :: ATTR_PERSISTENT连接,都将对其进行缓存,因此您也不必打扰。


I'm using symfony 1.4/propel 1.4 for a project, which was made by other developer earlier. On that project, propel connection is taken by using following code

$con = Propel::getConnection(UsersPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);

However it never closes the connection using

Propel::close();

I just searched that there are 1500+ such incidents of opening connection & I guess none of them is closing connection.

I know its always good practice to close connection but in present case, it seems I wont be able to fix them all as fixing all the incidents is definitely going to take lot of time, may be a whole day. So now I'm confused if I should fix that or not. If I let it be like that, will it have any performance impact?

EDIT: Just for reference

Part 2 of this question Use of closing database connection in php

解决方案

If anything, explicitly closing connections may harm performance. PDO often caches connections from one request to the next, on the reasonable assumption that the next request will use the same credentials.

Edit: reading the docs, it looks to me like PDO::ATTR_PERSISTENT connections are cached regardless of any attempt to close them, so you might as well not bother.

这篇关于不关闭推进连接的性能影响的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆