html - Reduce PHP execution time -


i have php script retrieves information via api games high scores. problem each player takes around half second , amount of users continuing add more 100 takes 50 seconds page load, long. there way can reduce loading time, or have store data after retrieve , update every 30 minutes or so.

this code:

    ($i = 0; $i <= $totalmembers - 1; $i++) {         $currentline = $lines[$i];         $data = explode("\t", $currentline);         $nameparsed = rawurlencode($data[1]);          $c = curl_init('http://services.runescape.com/m=hiscore_oldschool/index_lite.ws?player=' . $nameparsed);         curl_setopt($c, curlopt_returntransfer, true);         curl_setopt($c, curlopt_timeout, 0);          $html = curl_exec($c);         //$htmltrimmed = trim($html);         $oneline = trim(preg_replace("/[\n\r]/", ",", $html));          if (curl_error($c))             die(curl_error($c));          // status code         $status = curl_getinfo($c, curlinfo_http_code);         if ($status != 404){             $userinfo = explode(",", $oneline);              $base = 0.25 * ($userinfo[7] + $userinfo[13] + floor($userinfo[19]/2));             $melee = 0.325 * ($userinfo[4] + $userinfo[10]);             $range = 0.325 * (floor($userinfo[16]/2) + $userinfo[16]);             $mage = 0.325 * (floor($userinfo[22]/2) + $userinfo[22]);             $classlevel2 = max($melee, $range, $mage);             $final = floor($base + $classlevel2);             $totalcombat += $final;         }         curl_close($c);     } 

you should not rely on third-party web-site building own content. block if server makes many requests; when several visitors open page around same time example.

instead, should schedule background job (using cron on linux or task scheduler on windows) periodically records (or updated ones if possible) , add / replace these in own database.

then can serve content own database instantaneous. , control how many requests making external web-site, reducing risk of ending on blacklist.


Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -