Re: Close MySQL Result

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Daevid Vincent wrote:
>> -----Original Message-----
>> From: Nathan Rixham [mailto:nrixham@xxxxxxxxx] 
>>
>> you'll also find a performance upgrade if you load all sql 
>> results in to
>> an array and close up the query / free the results before 
>> working on them.
>>
>> query
>> for() {
>>   $results[] = $row;
>> }
>> close stuff
>> work on results
> 
> Do you have any proof of this? 
> What would be the logic here? 
> Got some example benchmarks?
> Got a URL of a whitepaper or something that discusses this?
> 
> I would think the only things that the mysql calls are doing is holding
> pointers to the next record and DB handle. I can't imagine they are using
> that much resources, nor would they be just spinning and waiting tying up
> CPU cycles either.
> 
> 
> I've never heard this to be the case.
> 

I have proof to the contrary :-)

<?php
echo number_format(memory_get_usage()) . " Bytes used before query\n";

$conn = mysql_connect('localhost', 'x', 'x');
$result = mysql_query("SELECT * FROM table_name");
$count = mysql_num_rows($result);

echo $count . " rows returned\n";

echo number_format(memory_get_usage()) . " Bytes used after query\n";

while($rows[] = mysql_fetch_assoc($result)) { }

echo number_format(memory_get_usage()) . " Bytes used after array
creation\n";

mysql_free_result($result);

echo number_format(memory_get_usage()) . " Bytes used after
mysql_free_result\n";
?>

65,588 Bytes used before query
6940 rows returned
67,264 Bytes used after query
6,376,612 Bytes used after array creation
6,376,756 Bytes used after mysql_free_result

-- 
Thanks!
-Shawn
http://www.spidean.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux