php连接mysql效率的一个疑问

WBOY
Release: 2016-06-06 20:47:18
Original
1031 people have browsed it

今日做了一个测试:

同样的代码,在本机上测试运行很快,但是放到了服务器上,则需要大约5-6秒左右的时间

代码如下:

<code class="lang-php">$username="infouser";
$userpass="it123";
$dbhost= "localhost";

$db_connect=mysql_connect($dbhost,$username,$userpass) or die("Unable to connect to the MySQL!");
mysql_select_db('syinfo');
</code>
Copy after login
Copy after login

本机环境:windows xp , XAMPP
服务器环境:windows 2008, XAMPP

$dblost="localhost" 改成了 $dblost="127.0.0.1";
速度就提升了不少

这是为什么?

回复内容:

今日做了一个测试:

同样的代码,在本机上测试运行很快,但是放到了服务器上,则需要大约5-6秒左右的时间

代码如下:

<code class="lang-php">$username="infouser";
$userpass="it123";
$dbhost= "localhost";

$db_connect=mysql_connect($dbhost,$username,$userpass) or die("Unable to connect to the MySQL!");
mysql_select_db('syinfo');
</code>
Copy after login
Copy after login

本机环境:windows xp , XAMPP
服务器环境:windows 2008, XAMPP

$dblost="localhost" 改成了 $dblost="127.0.0.1";
速度就提升了不少

这是为什么?

当主机填写为localhost时mysql会采用 unix domain socket连接
当主机填写为127.0.0.1时mysql会采用tcp方式连接

localhost代表你本地的DNS
DNS代表的是域名系统
当你输入你的域名的时候,就会向DSN主机进行查询,然后返回响应的IP地址。
LOCALHOST返回的是127.0.0.1则代表的是你本地的IP

从网上看到的
:-P

hosts里加一句

127.0.0.1 localhost
Copy after login

完事。

服务器是IPv6?

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!