Get size of MySql result set from query using PHP

Is it possible to get the result-set size when executing a request?

I need to install the correct MySql cache_limit(MB), and therefore I am trying to fulfill some requests, but I need to know the result-sets sizes to fine tune the cache settings.

What exactly does it do query_cache_limitwhen measuring the size of a request (or result) ...

Any help appreciated!

thank

+3
source share
3 answers

As a rouph score, you are trying to try

<?php
// 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

unset($a);

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

?>

or

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

+2
source

, mysql, php-:

SQL

SHOW SESSION STATUS . , :

Bytes_received  191
Bytes_sent      120

SHOW SESSION STATUS, .

mysqlnd

PHP 5.3 "MySQL Native Driver", .

, mysqli_get_connection_stats. :

Array
(
    [bytes_sent] => 43
    [bytes_received] => 80
    ...

mysqli mysqlnd, , SQL-.

+4

I suggest that the Petach method of using memory_get_usage before and after is probably the easiest way. To get a more accurate result, you can use mb_strlen, but you will need to scroll through each row in the result and each field of each row, summing up the total when you go. You will also need to use the correct encoding.

http://us3.php.net/manual/en/function.mb-strlen.php

0
source

Source: https://habr.com/ru/post/1732000/


All Articles