Slow response PHP API


I'm doing a project with band profiles. I'm trying to use the API.

For test base I downloaded the PHP API:

The classes I left in Root/src/classes.php, and started using Artist::search($artistName,$limit);

But I want to show only the bands registered in the bank. The script actually works, but the response from the site takes 7 seconds to return . I'm no "expert", so if anyone has an idea how to optimize this script.

            <div class="grid-cont">
            <div class="banda_search">
                <!-- hot news -->

                <form action="#">
                        <i class="fa fa-search"></i>
                        <input type="text" placeholder="Pesquise pelo nome da banda que você procura!">



                    $getPage = (!empty($Link->getLocal()[1]) ? $Link->getLocal()[1] : 0);
                    $Pager = new Pager(HOME . '/bandas/');
                    $Pager->ExePager($getPage, 12);

                    $readbanda = new Read;
                    $readbanda->ExeRead("ws_bands", "WHERE band_parent IS NOT NULL ORDER BY band_date DESC LIMIT :limit OFFSET :offset", "limit={$Pager->getLimit()}&offset={$Pager->getOffset()}");

                      if (!$readbanda->getResult()):
                          WSErro("Desculpe, não existem bandas cadastradas no momento, favor volte mais tarde!", WS_INFOR);

                            echo'<div class="banda_news">';
                            echo'<div class="grid-row">';
                            foreach ($readbanda->getResult() as $banda):

                               $results = Artist::search($band_title,"1");

                                   foreach($results as $artist):

                                        echo'   <div class="grid-col grid-col-3">
                                        <a href="'.HOME.'/banda/'.$band_name.'" class="small" alt="'.$band_title.'" title="'.$band_title.'">
                                        <span class="pic" alt="'.$band_title.'" title="'.$band_title.'" style="background-image: url(' . $artist->getImage(4) . ')"></span>



                            echo '</div>
                    $Pager->ExePaginator("ws_bands", "ORDER BY band_date");
                    echo $Pager->getPaginator();?>


If anyone has a better idea of ​​getting artists' images through the API and it's faster, I appreciate it.


To optimize the application, group all band names into a string and use the "IN" query in the conditional WHERE of your bank's query. This will make you only make 1 query to the bank, avoiding a few seconds of waiting between request and response.

Build the set values ​​for IN():

$bands = $readbanda->getResult();
$bands_sql = '';
for($i = 0; $i < count($bands); $i++){
    $bands_sql .= '\''.$bands[$i]['band_title'].'\'';
    $bands_sql.= ',';

This piece of code should generate a string with the name of all bands, now you should create a function to query your database, it should look like this:

SELECT * FROM bands WHERE band_title IN ($bands_sql);

The return of this query should be exactly what is being done today, but with time optimizations. Hope this helps.

Scroll to Top