PDO构造函数很慢(mysql) [英] PDO constructor very slow (mysql)

查看:283
本文介绍了PDO构造函数很慢(mysql)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这段代码需要几秒钟的时间才能执行。

This bit of code is taking almost a half second to execute. Could somebody help me with some reasons this could be happening and some possible solutions?

如果重要的是,数据库由amazon rds托管

If it matters, the DB is hosted by amazon rds

        $this->_connection = new PDO(
            $dsn,
            $this->_config['username'],
            $this->_config['password'],
            $this->_config['driver_options']
        );


推荐答案

PDO的构造函数打开数据库连接。当数据库在远程服务器上时,半秒(500毫秒)的暂停时间不会令人惊讶,因为ping时间和你不只是打开一个连接,还要登录连接。

PDO's constructor opens a database connection. When the DB is on a remote server, a half second (500ms) pause isn't too surprising, given ping times and the fact that you're not just opening a connection, but also logging in to it.

这篇关于PDO构造函数很慢(mysql)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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