php connecting to mysql server(localhost) very slow

Posted by Ahmad on Stack Overflow See other posts from Stack Overflow or by Ahmad
Published on 2011-01-07T04:22:20Z Indexed on 2011/01/07 4:54 UTC
Read the original article Hit count: 203

Filed under:
|
|
|

actually its little complicated:

summary: the connection to DB is very slow.

the page rendering takes around 10 seconds but the last statement on the page is an echo and i can see its output while the page is loading in firefox (IE is same). in google chrome the output becomes visible only when the loading finishes. loading time is approximately the same across browsers.

on debugging i found out that its the DB connectivity that is creating problem. the DB was on another machine. to debug further. i deployed the DB on my local machine .. so now the DB connection is at 127.0.0.1 but the connectivity still takes long time.

this means that the issue is with APACHE/PHP and not with mysql. but then i deployed my code on another machine which connects to DB remotely.and everything seems fine.

basically the application uses couple of mod_rewrite.. but i removed all the .htaccess files and the slow connectivity issue remains..

i installed another APACHE on my machine and used default settings. the connection was still very slow.

i added following statements to measure the execution time

    $stime = microtime();  
    $stime = explode(" ",$stime);  
    $stime = $stime[1] + $stime[0];  

// my code -- it involves connection to DB

    $mtime = microtime();  
    $mtime = explode(" ",$mtime);  
    $mtime = $mtime[1] + $mtime[0]; 

    $totaltime = ($mtime - $stime);
    echo $totaltime;

the output is 0.0631899833679

but firebug Net panel shows total loading time of 10-11 seconds. same is the case with google chrome

i tried to turn off windows firewall.. connectivity is still slow

and i just can't quite find the reason.. i've tried multiple DB servers.. multiple apaches.. nothing seems to be working.. any idea of what might be the problem?

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql