使用PHP,Zend Framework和PostgreSQL进行连接池 [英] Connection pooling with PHP, Zend Framework and PostgreSQL

查看:92
本文介绍了使用PHP,Zend Framework和PostgreSQL进行连接池的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

环境:单独服务器上的PostgreSQL 9.2,PHP 5.3,Zend Framework 1

Environment: PostgreSQL 9.2 on separate server, PHP 5.3, Zend Framework 1

我每分钟在几台服务器上执行数百个PHP脚本(从shell启动,不是作为WWW服务器请求),这些脚本在Zend Framework pdo_pgsql 与PostgreSQL的连接中使用.平均脚本执行时间约为15秒,大多数情况下,它们不使用数据库.现在,每个脚本都在开头打开数据库连接,并在结尾关闭它.它效率低下,所以我决定脚本在执行期间将关闭并重新打开数据库连接几次.

I execute on few servers every minute hundreds PHP scripts (launched from shell, not as WWW server request) which use in Zend Framework pdo_pgsql connection to PostgreSQL. Average script execution time is about 15s, most of the time they don't use database. Right now each script opens database connection at the beginning and closes it at the end. It is inefficient so I decided that script will close and reopen db connection few times during execution.

但是重新打开与数据库的连接效率也很低.由于我的PHP脚本是作为单独的进程(而不是作为WWW服务器工作程序)运行的,因此无法使用PHP持久连接.在我看来,最好的解决方案是在每台服务器上使用连接池系统,该系统将为PHP脚本存储与PostgreSQL的连接.

But reopening connection to database in also inefficient. PHP persistent connection is impossible to use because of my PHP scripts run as separate processes (not as WWW server worker). In my opinion the best solution will be using connection pooling system on each server, which will store connections to PostgreSQL for PHP scripts.

我是对的吗?如果是,您建议与PHP,Zend Framework( pdo_pgsql 适配器)和PostgreSQL一起使用哪个连接池系统?

Am I right? If yes, which connection pooling system do you recommend to use with PHP, Zend Framework (pdo_pgsql adapter) and PostgreSQL?

推荐答案

PgBouncer 非常适合这个工作.如果在会话池模式(默认)下使用,它将减少连接开销,而不会增加其他不必要的复杂性.更积极的池化模式(例如事务池或语句池)的确会影响客户端应用程序,因此只有在实际需要时才应使用它们.

PgBouncer is ideal for this job. It'll reduce connection overhead without adding other unnecessary complexity if used in session pooling mode (the default). The more aggressive pooling modes like transaction- or statement-pooling do affect the client application so you should only use them if you actually need them.

如James所指出的,可以在PostgreSQL Wiki上的 中找到更多信息.

More information can be found on the PostgreSQL wiki as James points out.

这篇关于使用PHP,Zend Framework和PostgreSQL进行连接池的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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