Can you really get how big the result-set when you are performing a question?

I have to set an effective MySql cache_limit (Megabytes) and for that reason I'm testing out some queries, but I have to be aware of dimensions from the result-sets to fine-tune my cache designs.

Just what does query_cache_limit do when calculating how big a question (or result)...

Any help appreciated!


Like a rouph estimate you coud try

// This is only an example, the numbers below will
// differ depending on your system

echo memory_get_usage() . "\n"; // 36640

$a = mysql_fetch_assoc($result);

echo memory_get_usage() . "\n"; // 57960


echo memory_get_usage() . "\n"; // 36744



echo strlen(serialize(mysql_fetch_assoc($result)));

In my opinion Petah's approach to using memory_get_usage pre and post is most likely the simplest way. To obtain a better result, you could utilize mb_strlen but you'd have to loop through each row within the result and every area of every row, summing in the total along the way. You'd should also make use of the correct encoding.

You will find a number of ways to measure how big data sent out of your mysql server for your php process:

Pure SQL

Do your query and execute SHOW SESSION STATUS directly after it. You're going to get several statistics, such as the sent and received bytes:

Bytes_received  191
Bytes_sent      120

Take away the bytes from the SHOW SESSION STATUS query alone, and you've got the precise values.


PHP 5.3 provides the "MySQL Native Driver", which provides you some nice choices to debug your connection.

Do your query after which call mysqli_get_connection_stats. It returns the network statistics, too:

    [bytes_sent] => 43
    [bytes_received] => 80

You should utilize mysqli and mysqlnd here, however, you have more accurate amounts just like the pure SQL solution.