PHP: Measure size in kilobytes of a object/array? PHP: Measure size in kilobytes of a object/array? php php

PHP: Measure size in kilobytes of a object/array?


Well, since Memcached doesn't store raw objects (it actually stores the serialiezd version), you can do this:

$serializedFoo = serialize($foo);if (function_exists('mb_strlen')) {    $size = mb_strlen($serializedFoo, '8bit');} else {    $size = strlen($serializedFoo);}


Another easy way pute content of array to file and then check file size.

$str = print_r($array, true);file_put_contents('data.txt', $str);$size = filesize('data.txt');