Delay in loading PHP page with image

Asked

Viewed 1,132 times

2

I have a PHP page that loads the 570 records in 2 seconds.

The problem is that when I insert images, even small (3 KB) the charging time goes to 10 seconds.

Is there any way to upload these images?

    <?php 
    while($consulta1 = mysql_fetch_array($result1)){;  
    ?>

    <div class="relacao">
      <div class="nome-album-artista"><?php echo $consulta1["nm_album"].'<br><i>'.$consulta1["nm_cantor"].'</i>'; ?></div>
    </div>

    <div id="botoes">
      <div class="btn_alterar"><a href="album_alterar.php?album=<?php echo $consulta1["id_album"]?>" title="Alterar"><img src="images/valid-icon.png"></a></div>
    </div>

    <?php
    }
    mysql_free_result($result1); 
    mysql_close($conn)
    ?>
  • If the only image used is "images/Valid-icon.png" and it has 3K there really is no reason to delay save some communication problem or on the server. Or there is something else wrong elsewhere. That is, the problem is probably something that is not apparent in this snippet of code. Or I ate ball in something.

  • Do you have anything specific that might be disturbing the shipment? From my point of view it was supposed to be normal

  • Must be while infinite loop, no?

  • bigown, actually it is not always this image, I carry the album covers according to select, just put this image there to test, because it is much smaller

  • André Ribeiro, I think not, because I removed the link from the image and the loading time was the same...

  • @Guilhermehenrique, worse than I could identify anything :/

  • @Wallacemaxters, I believe not. Because if I remove the images it loads super fast

  • @Ricardo is there, if you put a code different from the one that is giving problem, it is difficult to analyze, this can be ok and the real can be in trouble. If you are loading 570 different images (or at least different Urls even if each has 3K, it will be almost 2MB and there justifies the time.

  • @bigown but the code I posted is giving the problem I mentioned, it’s taking about 10 seconds to load. Before, when using the album cover was taking about 20 seconds. Then I removed the image and then I switched to this to see if it reduces the time, understood?

  • There is no problem in the code presented and I find it unlikely that someone can find what is the problem that should be elsewhere.

  • Would you be able to post the print of the loaded page showing the tag (network) ? it will display how long each action took

  • @Paulohdsousa, from Firebug you say?

Show 7 more comments

3 answers

3

You may not find the solution to your problem here, as it is a very different case that addresses many theories about networks, memory, etc.. So delete all possibility the problem is in your code.

However, I’d like to introduce Yslow as ANSWER to your question. It offers suggestions to improve the performance of the page and summarizes the components of your page.

Yslow analyzes web pages and why they are slow. Made for high performance websites.

Download: http://yslow.org/

Source: https://stackoverflow.com/questions/1559355/how-can-i-speed-up-image-load-time-in-my-web-site

3


One more possibility for you is to upload the images only when they are really needed. A project called Lazy Load (jQuery) does just that. It will cause the images to be loaded only when they are in the user’s viewport.

Project website:

http://www.appelsiini.net/projects/lazyload

  • I didn’t know this Lazy Load, it was perfect!

  • I’m glad I could help :)

1

Before trying to optimize, need to know what happens.

In the case of PHP and Mysql (the other BDD), we have 4 points:

  1. treatment time on the BDD side
  2. PHP side processing time
  3. data transmission time between server and browser
  4. time of page construction by browser

For point 1 vc can check using this:

 $start_time = microtime(true);   // Antes
 $result = @mysqli_query($handle,$query);
 $end_time = microtime(true);   // Depois
 $ecart = $end_time - $start_time;  // Diferença

For point 2, you can do it the same way: put a microtime(true) at the beginning of the PHP page, one at the last line, calculate the difference and make an "echo" of the result.

After that, you will be able to see if the exposure time is identical to that of the calculation: if the time of "PHP" is 0.03 second, the Mysql time of 0.01 it takes 3 seconds to see the page, it means that the problem does not happen in Point 1 or in Point 2...

About Point 4, there is one thing to know: I don’t know the structure of your page, but the browsers start showing the contents of the pages with tables, only after receiving the whole code. For example, if you have 500 results (after the query) and you put the results in one table (then you have the TABLE tag at the beginning of the page, then 500 TD and TR tags for the 500 results and at the end of the page the TABLE lock tag)The browser will expect to receive the 500 data BEFORE starting to show anything. To avoid this, you need to open and close the table, for example every 30 results. Thus, the user will quickly see the first 30, when the other results will continue to arrive. This will not change the "real" time but will change quite the perception of time!

Last chance: your internet connection is weak.

PS: a detail. "mysql" module is considered obsolete. Need to use mysqli.

  • Thanks for the Mysqli tip

Browser other questions tagged

You are not signed in. Login or sign up in order to post.