I just included some logging into my application. For testing purpose, I filled the database with some test values (basically the same row over and over again, about 27k rows..).
Now I wanted to print the data on a view, doing this:
<table id="chatLogs">
<thead>
<tr>
<th>ID</th>
<th>Message ID</th>
<th>User Agent</th>
<th>IP:Port</th>
</tr>
</thead>
<tbody>
<?php
foreach($chatlogs as $log){ ?>
<tr>
<td><?=$log['ID'];?></td>
<td><?=$log['messageID'];?></td>
<td><?=$log['userAgent'];?></td>
<td><?=$log['IP'];?></td>
</tr>
<?php }
?>
</tbody>
</table>
$log
is a variable I'm getting using the Database-Interface called Medoo.
Additionally, I included jQuery DataTables
for better and sortable tables.
<script>
$(document).ready( function () {
$('#chatLogs').DataTable({
dom: 'Bfrtip',
buttons: [
'copy', 'excel', 'pdf'
]
});
} );
</script>
Now, until everything is done and the page is fully loaded, it takes about 15 seconds (with the 27k test-rows). I just tested the same query directly on the database, and it takes 0.02 seconds, so its definetely about the PHP, not about the SQL.
And it seems like echoing everything in the table takes some time, as well as "loading it into DataTables"...
Now the question is: Is it possible to have it loading faster or instantly, and load the data, when its needed? I mean like only load the data into JSON and not echoing everything first (which is the longest part)? Because in the table, there are only 10 rows first anyway, and everytime I click on the next page, it could render it. Ofcourse though, all data would still need to be available for search.
Any ideas?