There are certain functions in the functions.php file that are connected to the index file as follows:
require('php/functions.php'); $geo = LocateUserGeo(); $popular = findPopularDirection(); And then, I draw the output in blocks using foreach:
$start = microtime(true); if( $popular['success'] ) { $i = 0; foreach($popular['data'] as $type => $item) { $dest = iataToCity($item['destination']); $orig = iataToCity($item['origin']); $imageurl = searchImage(iataToCity($item['destination'], 'en')); $currency = getCurrencyCode($geo['country_name']); if(++$i == 4) break; ?> <div class="col-sm-4 col-md-4 col-xs-12"> <div class="card"> <div class="card-image" style="background: transparent url('<?php echo $imageurl; ?>') no-repeat 50% 50%; background-size: cover;"> <span class="city-name"><?php echo $dest;?></span> </div> <div class="card-content"> <div class="flight-main-info"> <div class="origin"> <h6><?php echo $orig;?><span><?php echo $item['origin']; ?></span></h6> </div> <div class="destination"> <h6><?php echo $dest;?><span><?php echo $item['destination']; ?></span></h6> </div> </div> <div class="flight-details"> <div class="airline-logo"> <img src="//pics.avs.io/176/58/<?php echo $item['airline']; ?>.png" alt="" title="" /> </div> <div class="detail"> <span class="name">ΠΠΎΠ»-Π²ΠΎ ΠΏΠ΅ΡΠ΅ΡΠ°Π΄ΠΎΠΊ</span><span class="info"><?php echo $item['transfers']; ?></span> </div> <div class="detail"> <span class="name">ΠΠ°ΡΠ° ΠΎΡΠΏΡΠ°Π²ΠΊΠΈ</span><span class="info"><?php echo $item['departure_at']; ?></span> </div> <div class="detail"> <span class="name">ΠΠ°ΡΠ° Π²ΠΎΠ·Π²ΡΠ°ΡΠ΅Π½ΠΈΡ</span><span class="info"><?php echo $item['return_at']; ?></span> </div> <div class="detail"> <span class="name">Π¦Π΅Π½Π°</span><span class="info"><?php echo number_format($item['price'], 0, '.', ' '), ' ', $currency; ?></span> </div> </div> </div> <div class="card-action"> <div class="action-buttons"> <a href="#">ΠΠΎΠ΄ΡΠΎΠ±Π½Π΅Π΅</a> </div> </div> </div> </div> <?php } } else { echo '<h4 style="color: #9e9e9e;">Π£ΠΏΡ, ΠΏΡΠΎΠΈΠ·ΠΎΡΠ»Π° ΠΎΡΠΈΠ±ΠΊΠ° :(</h4>'; } echo 'ΠΠΎ ΠΎΠΏΡΠΈΠΌΠΈΠ·Π°ΡΠΈΠΈ: 2.22 ΡΠ΅ΠΊ.<br>'; echo 'ΠΠΎΡΠ»Π΅ ΠΎΠΏΡΠΈΠΌΠΈΠ·Π°ΡΠΈΠΈ: '.(microtime(true) - $start).' ΡΠ΅ΠΊ.';?> By design:
$start = microtime(true); //ΡΠ΅Π»ΠΎ ΡΠΊΡΠΈΠΏΡΠ° echo 'ΠΠΎΡΠ»Π΅ ΠΎΠΏΡΠΈΠΌΠΈΠ·Π°ΡΠΈΠΈ: '.(microtime(true) - $start).' ΡΠ΅ΠΊ.';?> I determined that the functions work takes from 0.03 to 0.1 seconds, but the output takes 2.2-3.1 seconds. What is the problem of such a long withdrawal?
searchImage(iataToCity($item['destination'], 'en'))using iataToCity, if you already have a destination city in the variable dest, a slight increase in speed will be, but still ... - MikegetCurrencyCode($geo['country_name']);is calledgetCurrencyCode($geo['country_name']);if the $ geo variable inside the cycle does not change, then the currency can be obtained once before the cycle - Mike