PHP中的连接池 [英] Connection pooling in PHP
问题描述
使用PHP时是否可以像在J2EE容器中那样缓存数据库连接?如果可以,怎么办?
Is it possible to cache database connections when using PHP like you would in a J2EE container? If so, how?
推荐答案
php中没有连接池.
mysql_pconnect 和连接池是两件事.
mysql_pconnect
有很多问题,首先您应该阅读并仔细使用它,但这不是连接池.
There is no connection pooling in php.
mysql_pconnect and connection pooling are two different things.
There are many problems connected with mysql_pconnect
and first you should read the manual and carefully use it, but this is not connection pooling.
连接池是一种应用程序服务器管理连接的技术.当应用程序需要连接时,它会向应用程序服务器请求连接,如果有一个空闲连接,则应用程序服务器将返回其中一个池连接.
Connection pooling is a technique where the application server manages the connections. When the application needs a connection it asks the application server for it and the application server returns one of the pooled connections if there is one free.
为此,我们可以使用php进行连接扩展: http://www.oracle.com/technetwork/articles/dsl/white-php-part1-355135.html
We can do connection scaling in php for that please go through following link: http://www.oracle.com/technetwork/articles/dsl/white-php-part1-355135.html
因此php中没有连接池.
So no connection pooling in php.
正如Julio所说,当对当前请求的请求结束时,apache释放所有资源.您可以使用mysql_pconnect,但是该功能受到限制,必须非常小心.另一种选择是使用单例模式,但这都不是池化.
As Julio said apache releases all resources when the request ends for the current reques. You can use mysql_pconnect but you are limited with that function and you must be very careful. Other choice is to use singleton pattern, but none of this is pooling.
这是一篇很好的文章: https://blogs. oracle.com/opal/highly-scalable-connection-pooling-in-php
This is a good article: https://blogs.oracle.com/opal/highly-scalable-connection-pooling-in-php
也请阅读 http://www.apache2.es/2.2. 2/mod/mod_dbd.html
这篇关于PHP中的连接池的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!