开发者

What is the typical speed that PHP connects to MySQL?

Say I have very standard mysql connection code:

$dbhost = '192.168.1.99';
$dbuser = 'dbuser';
$dbpass = 'dbuserpass';
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die('Error connecting to mysql');
$dbname = 'mydb';
mysql_select_db($dbname);

This would connect from the web server to the database server (say the web 开发者_运维百科server is at 192.168.1.98 or something). Typically, how long would the above code run? Currently, I'm seeing about 2 seconds. Is that slow?


One possibility is that mysql is doing a DNS lookup to find the name of the connecting server; depending on your setup, this could take a long time. There's not really much benefit to it, aside from being able to specify the users by hostname rather than IP address (e.g. user@example.com rather than user@192.168.1.1).

This can be disabled in the configuration or when starting up MySQL with the --skip-name-resolve parameter. More information is available on the MySQL site.


2 seconds does seem slow, but it depends on your server and database server. Depending on what else they are doing, where they are located and many other factors it could actually be fast.

I usually get times of less than a second.


For local LAN, unless you're using antiquated equipment, or something is wrong, it should typically be on the order of (a) millisecond(s).


Do you have lots of tables? It may be spending time looking around after connecting. Is the command line mysql client slow too? Is it fast if you're connecting from localhost?


That is very slow. On avarage websites, the entire page renders within two seconds. That is, connecting to the database, running the queries, retrieving results and rendering the page.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜