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

前端 未结 2 577
攒了一身酷
攒了一身酷 2020-12-29 06:01
  • What\'s an appropriate way of measure a PHP objects actual size in bytes/kilobytes?

Reason for asking:
I am utilizing memcached for cache storage in

2条回答
  •  旧巷少年郎
    2020-12-29 06:46

    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);
    }
    

提交回复
热议问题