Site is very slow

Asked

Viewed 406 times

1

This site uploads files . torrent, downloads, opens Magnet, takes Seeds, leechers, etc, but it is VERY SLOW, it takes about 15 seconds to open.

what I can do to reduce that time?

        if($sql = mysqli_query($coneccao, "SELECT * FROM arquivos_downloads WHERE nome LIKE '%$palavra_chave%' ORDER BY id DESC"))
        {   
            while($linha = mysqli_fetch_array($sql))
            {
                if($i == $linha['id'] || $i != $linha['id'])
                {   
                    $arq = $linha['nome'];

                    $arq_title = $arq;

                    $arq_nome = substr($linha['nome'], 0, 50);
                    $arq_nome = str_replace("_", " ", $arq_nome);

                    for($icont = 0; $icont <= 100; $icont++)
                    {
                        $arq_nome = str_replace("[".$icont."]", "", $arq_nome);
                        $arq_title = str_replace("[".$icont."]", "", $arq_title);
                    }

                    error_reporting(E_STRICT);

                    ini_set('user_agent', 'PHP');

                    $torrent = new Torrent("Uploads/".$arq.".torrent");
                    $torrentHash = $torrent->hash_info();

                    $SeedsLeechs = obterSeedLeech($torrentHash);
                    $SeedsLeechs = json_decode($SeedsLeechs);

                    if (is_array($SeedsLeechs))
                    {
                        foreach($SeedsLeechs as $anuncios)
                        {
                            $seeds = $seeds + $anuncios->NUM_SEEDERS;
                            $leechers = $leechers + $anuncios->NUM_LEECHERS;
                        }
                    }   
            ?>      
                //AQUI TEM UM MONTE DE DIV QUE NÃO ATRAPALHA
            <?       
                }
                $seeds = 0;
                $leechers = 0;
            }
        }
        ?>
  • Lucas, edit the question and leave only the code relevant so that someone can help you.

  • I just left the part that really slows down the site

  • Have you tried to analyze if the problem is in the bank consultation? To do this, you can run the query using Mysql Workbench (or similar) or calculate the time before and after the database calls.

1 answer

1

Try to close the PHP connections as soon as you finish making the query(). jQuery/Javascript put in a separate file saved with extension .js. Beware of extreme spaces (no need). Look at your code and think "is this really accurate?". But what I think is most important is the issue of closing the connections/actions after making the query(), In doing so, you will use less memory. If you have many images on your site or large images (type 1MB, 2MB, etc.) I recommend you use the site compressor.io it will help you and much in the matter of images.

  • Hello, I did some testing and really what generates slowness is that while, would have some way to let that while lighter ??

  • 1

    What I would do is decrease the number of loops that are inside your while() , because besides the while() has a for() with 1000 loops and then a foreach(). Try to see what you can do, it depends on the need of your system.

  • Actually, I agree with @Alissonacioli, decrease the number of loops within the while, seeing that the foreach is not even dependent, and as for the for I think it can be improved. Another thing is to set the field nome as INDEX in your table. For better analysis use the function microtime

Browser other questions tagged

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