Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/237.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何优化和提高MySQL查询的速度?_Php_Mysql_Database - Fatal编程技术网

Php 如何优化和提高MySQL查询的速度?

Php 如何优化和提高MySQL查询的速度?,php,mysql,database,Php,Mysql,Database,我正在尝试从数据库中获取信息并显示它。以下是该页面的屏幕截图: 页面加载速度非常慢 有没有办法让它更快地加载和显示数据 这是代码 <table align="center" class="pTable"> <tr class="main"> <th class="pTableHeader"> ID </th> <th class="pTableHeader"> Room </th> <th class="pTable

我正在尝试从数据库中获取信息并显示它。以下是该页面的屏幕截图:

页面加载速度非常慢

有没有办法让它更快地加载和显示数据

这是代码

<table align="center" class="pTable">
<tr class="main"> <th class="pTableHeader"> ID </th> <th class="pTableHeader"> Room </th> <th class="pTableHeader"> Status</th> </tr>
<?php
gc_enable();
gc_collect_cycles();
flush();
$this->mysql = new sqli('HIDDEN','HIDDEN','HIDDEN','HIDDEN');
$bots = $this->mysql->fetch_array("SELECT `pid`,`room`,`id` from `bots`;");
foreach ($bots as $b) { 
if(is_numeric($b["room"])) {
$xat = file_get_contents('http://www.xat.com/xat'.trim($b["room"]));
$name = sp($xat, '<h1>&nbsp;', '</h1>');
}
else $name = $b['room'];
//$b["pid"] = isset($b["pid"])?$b["pid"]:false;
//$online = \"start.php {$b['id']} {$b['id']}\"", $output) && count($output) > 1 ? true : false;
$online = file_exists("/proc/{$b['pid']}" )?true:false;
if($online === true) $status = "<font color='green'>Online</font>&nbsp;<div style='float:right'><img src='http://fexbots.com/Images/Pawns/online.png'>&nbsp;<a href='/botinfo?botid={$b["id"]}'>More info</a></div>";
else $status = "<font color='red'>Offline</font>&nbsp;<div style='float:right'><img src='http://fexbots.com/Images/Pawns/offline.png'>&nbsp;<a  href='/botinfo?botid={$b["id"]}'>More info</a></div>";
if($b["room"] === '') { 
$name = "No Room"; 
$status = "<font color='red'>Not Setup!</font>&nbsp;&nbsp;<div style='float:right'><img src='http://fexbots.com/Images/Pawns/hang.png'>&nbsp;<a  href='/botinfo?botid={$b["id"]}'>More info</a></div>";
echo '<tr> <td> '.$b["id"].' </td> <td> No Room <td> '.$status.'</td> </tr>';
}
else echo "<tr> <td> ".$b['id']." </td> <td> <a href='http://www.xat.com/$name'>$name</a> <td> ".$status."</td> </tr>";
}
function sp($content, $start, $end, $lower=false) {
if($lower!=false) {
$content = strtolower($content);
$start   = strtolower($start);
$end     = strtolower($end);
}
$content = substr($content, strpos($content,$start)+strlen($start));
$content = substr($content, 0, strpos($content,$end));
return $content;
}
?>
</table>

ID房间状态

您似乎是从循环中的URL下载内容。也许这就是为什么它很慢,而不是mysql查询本身的原因


试着写出一些时间戳或注释一些代码,看看是什么导致它变慢的

您确定是查询妨碍了性能吗?请缩进并格式化您的代码,因为人们帮助您的积极性将提高20倍。如果我不得不这样做,那么
$xat=file\u get\u contents('http://www.xat.com/xat“.trim($b[“房间]))是slowdown@MonkeyZeus:是的,我的想法正是……试试看回声日期('H:i:s')$xat=文件获取内容('http://www.xat.com/xat“.trim($b[“房间]));回音日期('H:i:s')要查看时间延迟是的,是文件内容,我测试了它。我怎么修理它?我需要下载,它也提供了一个时间延迟,20:53:4120:53:4320:53:4320:53:4320:53:4320:53:4420:53:4420:53:4520:53:4520:53:4520:53:46如果必须获得数据,很难降低加载时间。但是,如果您使用Ajax加载它,则可以为访问者提供更好的用户体验。然后页面将加载得更快,用户可以更快地看到页面——完成后,您可以开始使用Ajax加载每一行的状态。您可能需要创建一个新的PHP页面,将$b[“room”]作为参数,然后在单独的页面中执行file_get_内容。