PHP 8.5.0 Beta 2 available for testing

Voting

: max(zero, four)?
(Example: nine)

The Note You're Voting On

polygon dot co dot in at gmail dot com
3 years ago
We should free the mysql results using mysqli_free_result respectively or else this will consume your server RAM resource.

This is demonstrated as below

<?php

$link
= mysqli_connect('Hostname','Username','Password','Database');

echo
'<br/>Memory Usage Before Query = '.memory_get_usage(false); // 449464 bytes

$resultResource = mysqli_query($link, 'SELECT * FROM test');

echo
'<br/>Memory Usage after Query = '.memory_get_usage(false); // 466528 bytes

$result = array();
while (
$result[] = mysqli_fetch_assoc($resultResource)) {}

echo
'<br/><br/>Memory Usage Before Free Result = '.memory_get_usage(false); // 474208 bytes

mysqli_free_result($resultResource);

echo
'<br/>Memory Usage After Free Result = '.memory_get_usage(false); // 457336 bytes

?>

Output below.

Memory Usage Before Query = 449464
Memory Usage after Query = 466528

Memory Usage Before Free Result = 474208
Memory Usage After Free Result = 457336

So, One can observer there is memory usage after the query is executed. The results are returned by DB server to the web server instantaniously once the query execution is over. The results present on web server are then processed for fetching from the resource link on web server.

Also this is observed that there is lesser memory usage after using mysqli_free_result because the resources stored on web server for respective query are freed by providing respective resource link.

<< Back to user notes page

To Top