php串連mysql效率的一個疑問

來源:互聯網
上載者:User
今日做了一個測試:

同樣的代碼,在本機上測試回合很快,但是放到了伺服器上,則需要大約5-6秒左右的時間

代碼如下:

$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');

本機環境:windows xp , XAMPP
伺服器環境:windows 2008, XAMPP

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

這是為什嗎?

回複內容:

今日做了一個測試:

同樣的代碼,在本機上測試回合很快,但是放到了伺服器上,則需要大約5-6秒左右的時間

代碼如下:

$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');

本機環境: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

完事。

伺服器是IPv6?

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.