源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

Windows Server 2008 R2和2012中PHP连接MySQL过慢的解决方法

  • 时间:2020-05-26 06:03 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:Windows Server 2008 R2和2012中PHP连接MySQL过慢的解决方法
对比下面两个脚本的速度: [list] [*]Windows 7 用 localhost 连接本地 MySQL,速度会很慢。[/*] [*]Windows 7 用 127.0.0.1 连接本地 MySQL,速度则是正常的。[/*] [/list] my.ini里配置了
bind-address=127.0.0.1
 用localhost连接本地MySQL: 速度慢
<?php
$start = microtime(true);
$mysqli = new mysqli('127.0.0.1', 'root', '', 'mysql'); //连接耗时仅为0.0025秒.
//$mysqli = new mysqli('localhost', 'root', '', 'mysql'); //连接耗时超过1秒,比正常慢了400倍.
echo microtime(true) - $start;
[b]分析: [/b]1.my.ini里配置
bind-address=127.0.0.1
时,Win7及其以上版本系统PHP用localhost连接MySQL耗时超过1秒,比用127.0.0.1连接慢了400倍. 2.my.ini里配置
bind-address=::1
时,Win7及其以上版本系统PHP用localhost连接MySQL速度是正常的,但用127.0.0.1连接又不正常了. 3.去掉bind-address配置,则用localhost或127.0.0.1连接MySQL速度都是正常的. 所以:在配置了
bind-address=127.0.0.1 
的情况下,应该使用 127.0.0.1 连接本地 MySQL 数据库 。 安装 WordPress、phpMyAdmin 等 PHP 程序的时候默认使用 localhost 连接本地 MySQL 数据库,这时注意把默认的 localhost 改为 127.0.0.1。 另外,Windows 2008、2012 跟 Windows 7 存在同样的问题。
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部