【发布时间】:2011-03-24 03:06:41
【问题描述】:
我创建了一个简单的 PHP 测试页面,它连接到 MySQL 数据库,选择一个 int 值,然后释放结果。该页面需要 5 秒或更长时间才能加载。我看过很多关于这个或类似问题的帖子,但没有一个决议奏效。这是我得到的输出:
mysql_connect took 4.8948628902435 seconds
mysql_select_db 0.00073790550231934 seconds
mysql_query took 0.0013959407806396 seconds
mysql_free_result took 2.0980834960938E-5 seconds
如您所见,连接时间太长,其他一切都很快。
我尝试过的
- 禁用 IPv6
- 为 MySQL 主机使用 IP 而不是 FQDN。
- 调整了一些配置设置。
事实
- 所有其他非 PHP 网站都会立即响应。
- ping MySQL 服务器会产生 1 毫秒的延迟。
- 使用 MySQL 查询浏览器查询数据库可提供即时响应时间。
仅供参考 - 我不使用 PHP,所以在建议修复时可以像对待婴儿一样对待我。
测试脚本
<?php
$mtime = microtime();
$mtime = explode(' ', $mtime);
$mtime = $mtime[1] + $mtime[0];
$starttime = $mtime;
mysql_connect("the_ip||the_hostname", "the_username", "the_password");
$mtime = microtime();
$mtime = explode(" ", $mtime);
$mtime = $mtime[1] + $mtime[0];
$endtime = $mtime;
$totaltime = ($endtime - $starttime);
echo '<h2> mysql_connect took ' .$totaltime. ' seconds</h2>';
?>
跟踪路线是瞬时的: 顺便说一句,有问题的应用程序是MantisBT 以及 Wordpress。
1 2 ms <1 ms <1 ms 1.2.3.4
2 <1 ms <1 ms <1 ms MYSQL5 [5.6.7.8]
【问题讨论】:
标签: php mysql iis-7.5 performance