Jos*_* M. 4 php mysql performance iis-7.5
I've created a simple PHP test page which connects to a MySQL database, selects one int value, and then frees the result. The page takes 5 seconds or more to load. I've seen a lot of posts about this or similar issues but not of the resolutions have worked. Here is the output I'm getting:
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
Run Code Online (Sandbox Code Playgroud)
As you can see, the connection takes far too long and everything else is fast.
FYI - I don't do PHP so it's okay to treat me like a baby when suggesting fixes.
<?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>';
?>
Run Code Online (Sandbox Code Playgroud)
Trace route is instantaneous: By the way, the application in question is MantisBT as well as Wordpress.
1 2 ms <1 ms <1 ms 1.2.3.4
2 <1 ms <1 ms <1 ms MYSQL5 [5.6.7.8]
Run Code Online (Sandbox Code Playgroud)
另一件需要注意的是"mysql_connect",它可能会向您显示PHP很难解析(查找)mysql主机.您使用的是IP地址,localhost还是主机名?(当连接到php中的数据库时)如果是主机名,请尝试将IP添加到c:\ windows\system32\drivers\etc\host
如果这不起作用.如果您的所有"事实"都是正确的,那么您的PHP脚本可能会出现问题.你可以发布它,这样我就可以看到你在运行什么?同时发布mysql表信息,如"索引"等.
:)