2

I have a fresh "installation" of yii with a mysql database in the background.

If i want to get the db connection from the app:

$connection = Yii::app()->db;

it needs about 1 second to this.

Is there any trick to speed it up?

Community
  • 1
  • 1
rakete
  • 2,953
  • 11
  • 54
  • 108
  • 2
    Connecting to a database requires some time to establish. Usually applications have a database handle pool to recycle them between requests. What does Yii do for this? – tadman Oct 18 '12 at 15:25
  • 3
    This doesn't have to do with Yii, but rather with the particulars of your connection to the database. – Jon Oct 18 '12 at 15:27
  • I am sure it can't be 1 sec, it is very much high time, we get results below 1 sec..please debug correctly there may be another code that is taking high time. – Onkar Janwa Oct 22 '12 at 05:15
  • 2
    The answer is here ==> http://stackoverflow.com/questions/9800577/why-is-constructing-pdo-connection-slow/9800798#9800798 – Mario S Jun 20 '13 at 05:04
  • 1
    Mario S Fallen has the answer. It's not yii, rather your DNS table is the culprit. Change db host to 127.0.0.1 from localhost. Works for me too. – Gogol Jan 22 '14 at 06:30

1 Answers1

0

Debug to find the time used in Connecting to a database.

Test it using WebGrind.

I have tested it takes around 10ms for my case.

Onkar Janwa
  • 3,892
  • 3
  • 31
  • 47