Looping queries to an API is really slow

I’ve heard that it is possible to loop JSON datas by using only one query and not doing querries for every loop. Any ideas how to make this from this code?
I really need to do it because it takes up to 3 minutes to successfully load the page..

* PHP *

<?php foreach ($return as $user) {

                        $link = "http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=$devkey&steamids=$user->SteamID";
                        $json = file_get_contents($link);
                        $decoding = json_decode($json);
                        $avatar = $decoding->response->players[0]->avatar;
                        ?>
                        <td id="addme"><img src="<?php echo $avatar; ?>" width="32" height="32"></td>
                        <td><?php echo $user->DisplayName; ?></td>
                        <td><?php echo $user->SteamID; ?>  <a href="http://steamcommunity.com/profiles/<?php echo $user->SteamID; ?>/" target="_blank"><span class="glyphicon glyphicon-new-window" id="gotosteamprofile"></span></a></td>
                        <td><?php
                        $ipredc = substr($user->Address, 0, -6);
                        echo $ipredc; ?></td>
                        <td><?php 
                        $toconver = $user->ConnectedSeconds;
                        $hours = floor($toconver / 3600);
                        $mins = floor($toconver / 60 % 60);
                        $secs = floor($toconver % 60);
                        $timeFormat = sprintf('%02d:%02d:%02d', $hours, $mins, $secs);
                        echo $timeFormat;
                        ?></td>
                        </tr>

                    <?php
                    }
                    ?>


Source: stackoverflow-php

Array.forEach() and closure

After I read an article about JavaScript optimization, I realize there is a need to remove closures in the code to optimize the memory use.

One code pattern of mine is to use Array.forEach() as much as possible, even in such situations:

  • modify an external object using items in an array

    function updateSomething(array, toChange) {
      array.forEach(item => {
        toChange[item] = ''; // do something to change the object
      });
    }
    
  • create nested Array.forEach()

    array1.forEach(item1 => {
      array2.forEach(item2 => {
        doSomething(item1, item2);
      });
    });
    

Apparently the callback function used in the Array.forEach() creates closures. So am I abusing the Array.forEach() in these cases? Should I go back to for loop in performance-sensitive projects?


Source: stackoverflow-javascript