一週間前くらいからPHPとMySQLを初めて、ある程度わかってきたのでwebコンテンツを作っているわけですが、MySQLとPHPでうまく処理しないとページの表示が遅くなるということはいのんなページで見てきました。ですが、自分が思ってたより時間がかかります。
調べてみるとインデックスがどうのこうのとありましたが、いまいちパットイメージが湧きません。
とにかく、高速化&修正したほうが良い点を教えてください。お願いします。
いま制作しているものです。ソースファイルとリンク先はほとんど同じ内容です。
URL:http://reporthack.starfree.jp/
<?php require_once('private/conf.php'); try { $db = new PDO('mysql:host='.$db["host"].';dbname='.$db["dbname"].';charset=utf8', $db["user"], $db["pass"]); $stt = $db->prepare('SELECT * FROM cheaters ORDER BY datetime'); $stt->execute(); } catch(PDOException $e) { die('エラーメッセージ:'.$e->getMessage()); } ?> <!DOCTYPE html> <html> <head> <meta charset="utf-8"/> <link rel="stylesheet" type="text/css" href="css/main.css"> <title></title> </head> <body> <div id="header"> <a>PUBG CHEATERS</a> </div> <div id="content"> <div id="search"> <form> <input type="text" placeholder="Steam ID or PlayerName" class="box"> <button name="test" type="submit" class="btn">Search</button> <button name="test" type="submit" class="reBtn">Report</button> </form> </div> <table class="list"> <thead> <tr> <th>Icon</th> <th>Player Name</th> <th>Steam ID</th> <th>Date by reported</th> </tr> </thead> <tbody> <?php while ($row = $stt->fetch()) { $steamid = $row["steamid"]; $number = $row["number"]; $date = date("Y-m-d H:i:s",strtotime($row["datetime"])); $url = "http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=3568B95FD3BEDE9C821EB085B581DE57&steamids=".$steamid; $html = file_get_contents($url); $json = json_decode($html,true); $avatarurl = $json["response"]["players"][0]["avatarfull"]; $playername = $json["response"]["players"][0]["personaname"]; echo '<tr><td class="icon"><img src='.$avatarurl.'></img></td>'; echo "<td>".$playername."</td>"; echo "<td>".$steamid."</td>"; echo "<td>".$date."</td></tr>"; $stt2 = $db->prepare('UPDATE cheaters SET playername=:playername WHERE number=:number'); $stt2->bindValue(':number',$number); $stt2->bindValue(':playername',$playername); $stt2->execute(); } ?> </tbody> </table> </div> </body> </html>
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/11/25 12:18