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?

  • And how did you determine that functions work quickly? And this is the execution time of one function in one pass or the total for all, in all passes - Mike
  • @Mike checked each function separately, and then the speed at which the functions were connected to the index file. Everything happens quite quickly, the loading of functions takes 0.3 seconds. The problem is in the output. - JamesJGoodwin
  • And you run the full cycle just by commenting out the entire output and see the time - Mike
  • one
    Why, for example, are you here 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 ... - Mike
  • one
    Why inside of a loop getCurrencyCode($geo['country_name']); is called getCurrencyCode($geo['country_name']); if the $ geo variable inside the cycle does not change, then the currency can be obtained once before the cycle - Mike

0