note 126622 added to mysqli-result.free

From: Date: Fri, 19 Nov 2021 10:15:23 +0000
Subject: note 126622 added to mysqli-result.free
Groups: php.notes 
Request: Send a blank email to php-notes+get-217266@lists.php.net to get a copy of this message
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. ---- Server IP: 45.112.84.4 Probable Submitter: 45.112.85.242 (proxied: 103.58.152.190) ---- Manual Page -- https://php.net/manual/en/mysqli-result.free.php Edit -- https://main.php.net/note/edit/126622 Del: integrated -- https://main.php.net/note/delete/126622/integrated Del: useless -- https://main.php.net/note/delete/126622/useless Del: bad code -- https://main.php.net/note/delete/126622/bad+code Del: spam -- https://main.php.net/note/delete/126622/spam Del: non-english -- https://main.php.net/note/delete/126622/non-english Del: in docs -- https://main.php.net/note/delete/126622/in+docs Del: other reasons-- https://main.php.net/note/delete/126622 Reject -- https://main.php.net/note/reject/126622 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#217266) next »