そのため、この PHP コードを実行して結果を出力するのに時間がかかりすぎる理由を理解しようとしています。
たとえば、これは私のものapitest.php
で、ここに私のPHPコードがあります
<?php
function getRankedMatchHistory($summonerId,$serverName,$apiKey){
$k
$d;
$a;
$timeElapsed;
$gameType;
$championName;
$result;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://".$serverName.".api.pvp.net/api/lol/".$serverName."/v2.2/matchhistory/".$summonerId."?api_key=".$apiKey);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($ch);
curl_close($ch);
$matchHistory = json_decode($response,true); // Is the Whole JSON Response saved at $matchHistory Now locally as a variable or is it requested everytime $matchHistory is invoked ?
for ($i = 9; $i >= 0; $i--){
$farm1 = $matchHistory["matches"][$i]["participants"]["0"]["stats"]["minionsKilled"];
$farm2 = $matchHistory["matches"][$i]["participants"]["0"]["stats"]["neutralMinionsKilled"];
$farm3 = $matchHistory["matches"][$i]["participants"]["0"]["stats"]["neutralminionsKilledTeamJungle"];
$farm4 = $matchHistory["matches"][$i]["participants"]["0"]["stats"]["neutralminionsKilledEnemyJungle"];
$elapsedTime = $matchHistory["matches"][$i]["matchDuration"];
settype($elapsedTime, "integer");
$elapsedTime = floor($elapsedTime / 60);
$k = $matchHistory["matches"][$i]["participants"]["0"]["stats"]["kills"];
$d = $matchHistory["matches"][$i]["participants"]["0"]["stats"]["deaths"];
$a = $matchHistory["matches"][$i]["participants"]["0"]["stats"]["assists"];
$championIdTmp = $matchHistory["matches"][$i]["participants"]["0"]["championId"];
$championName = call_user_func('getChampionName', $championIdTmp); // calls another function to resolve championId into championName
$gameType = preg_replace('/[^A-Za-z0-9\-]/', ' ', $matchHistory["matches"][$i]["queueType"]);
$result = (($matchHistory["matches"][$i]["participants"]["0"]["stats"]["winner"]) == "true") ? "Victory" : "Defeat";
echo "<tr>"."<td>".$gameType."</td>"."<td>".$result."</td>"."<td>".$championName."</td>"."<td>".$k."/".$d."/".$a."</td>"."<td>".($farm1+$farm2+$farm3+$farm4)." in ". $elapsedTime. " minutes". "</td>"."</tr>";
}
}
?>
私が知りたいのは、結果を出力するのに約10〜15秒かかるため、ページの出力を高速化する方法です.500内部エラーなどのように、ブラウザはウェブサイトが死んでいると判断します.
これは、どれくらいの時間がかかるかの簡単なデモンストレーションです:ここ
お気づきかもしれませんが、はい、JSON エンコード タイプとして応答を送信する Riot API を使用しています。
この関数が処理する応答の例を次に示します。
私が考えたのはtemp.php
、CURL関数の開始時に呼び出される一時ファイルを作成し、そこに応答全体を保存し、そこから変数を読み取ってプロセスを高速化し、変数を読み取った後、作成されたファイルを削除しtemp.php
て解放することでしたディスク容量を増やします。そして速度を上げる。
しかし、PHPのみでそれを行う方法がわかりません。
ところで、私は今日 PHP を使い始めたばかりなので、可能であれば回答付きで説明したいと思います。
貴重な時間をありがとう。