views:

138

answers:

2

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?

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']
        );
A: 

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.

R. Bemrose
Thanks for the response. Does it seem like this would take away the advantage of using Amazon RDS in general?
Brian
this is a great reason to use persistent connections. on local networks, persistent connections are not worth the hassle. on slow networks, this is where they come in handy. just make sure that you add to your connection code/class to check if any transactions are open on the current connection and roll them back.
longneck
A: 

So how can we fix the code above to make it faster?