[英]How to get amount of data transfered between PHP and DB server from inside PHP code?
I want to analyze the amount of traffic certain scripts use when communicating with DB. 我想分析某些脚本在与DB通信时使用的流量。 I use mysqli_connect
, then I do mysqli_query
and then usually mysqli_fetch_assoc
or mysqli_fetch_array
. 我使用mysqli_connect
,然后我做mysqli_query
然后通常是mysqli_fetch_assoc
或mysqli_fetch_array
。 I want to know how many bytes are transferred for any given query. 我想知道为任何给定的查询传输了多少字节。 This will of course depend on how many times I call "fetch" methods. 这当然取决于我调用“fetch”方法的次数。 I can easily keep counters and sum them up, but how to get the correct values? 我可以轻松地保留计数器并总结它们,但如何获得正确的值?
The best thing I can think of is calculate size of array returned by these fetch functions. 我能想到的最好的事情是计算这些获取函数返回的数组的大小。 Given that there is no byte_size_of() function in PHP, Id have to foreach
through them and sum strlen()
of every single value. 由于有PHP中没有byte_size_of()函数,身份证必须foreach
通过他们和总和strlen()
的每一个值。 But this obviously is bad approach, since these values wont be exactly what is received. 但这显然是不好的方法,因为这些价值观并不完全是收到的。
Thanks for help! 感谢帮助!
Note: the answers in How to calculate size from my query MySQL? 注意: 如何从我的查询MySQL中计算大小的答案? or How to get the byte size of resultset in an SQL query? 或者如何在SQL查询中获取结果集的字节大小? do not answer how to get it from PHP. 不要回答如何从PHP获取它。 I cant edit eveyr query and do it this way, I need a way to get file size from withing the PHP. 我不能编辑eveyr查询并以这种方式执行,我需要一种方法来获取PHP的文件大小。
This function has bytes_sent
and bytes_received
in the output 此函数在输出中具有bytes_sent
和bytes_received
http://php.net/manual/en/mysqli.get-connection-stats.php http://php.net/manual/en/mysqli.get-connection-stats.php
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.