1

I am working on optimization of a php/mysql web application . The problem which I am facing is that the result of a function is really big ! like 4MB.

I call a function inside HTML-php file :

<table id="example1" class="table table-bordered table-striped table-hover" width="100%">
         <thead>
         <tr><th>
    .
    .
    .</thead>
<?php
$results = $diosAdminMain->getResults();
echo $results;
?>
</table>

and should get the results from my DB and then present them with help of Datatables.

inside my class file is my function

     <?php

        $diosAdminMain = new diosCore;

        class diosCore{ 

        public function getResults(){


                $myhtml='<tbody>';
                .
                .
                .
               $resultqry=mysql_query('SELECT * from table');

              while($row = mysql_fetch_assoc($resultqry)){ 
                 $myhtml.= '<tr>
                  <td>'.$row['ID'].'</td>
                  <td>'.$row['PR1'].'</td>
                  <td>'.$row['PR2'].'</td>
                  <td>'.$row['THL1'].'</td>
                  <td>'.$row['THL2'].'</td>
                  <td>'.$row['NAME1'].'</td>
                 <td>'.$row['NAME2'].'</td>';
               }

             $myhtml.='</tbody>';

             return $myhtml;
          }
     }
    .
    .    
    ?>

I try to figure out a way to make make this presentation faster because the results are going to grow more. Now for 1800 rows ,takes almost 20 secs to show on chrome.

By the measurements I took without the datatables it only saves me 1-2 secs( and I don't want to remove it as the fast search is awsome). I also tried to optimise the mysql queries and the logical flow inside function but the same result. So I exported the result of the function as a plain text and found out that is just a big result with 4MB size.

Is there a way to suppress somehow the size of the $myhtml variable to make things faster ? or any other way I missed ?

thanks

Community
  • 1
  • 1

1 Answers1

1

You should consider showing the results page by page. It is not possible to show a huge amount of data into a page without a performance impact. Showing 50 or a 100 rows per page will be much faster and will work with all amounts of data.

Gardax
  • 370
  • 1
  • 14
  • I think you suggest on using the server side proccessing https://datatables.net/examples/data_sources/server_side.html Is this going to have negative impact on datatables INSTANT search ?? – Manos Manoss Dec 22 '16 at 08:36
  • Yes, this is the way to go with Data Tables. It will have some impact on the search BUT it is definitely worth because the impact will be small enough not to worry about. And the initial load time will be much lower and will remain almost the same with all amounts of data(until the servers is overloaded of course). – Gardax Dec 22 '16 at 12:25