PHP如何查找memcached數組上的filesize

[英]PHP How to find out the filesize on an array for memcached


From what i have read, you can not store values or data over 1mb at a time with memcached. If this is the case, is there any way to find out the filesize of an array before submitting it to memcached?

根據我所讀到的,您不能使用memcached每次存儲超過1mb的值或數據。如果是這樣的話,在將數組提交到memcached之前,是否有方法可以找到數組的filesize ?

3 个解决方案

#1


1  

Memcache is a key/value store, and hence does not 'know' about more "complex" objects. What the module does is serialize the value & store that as a string. So, the total size = strlen(serialize($value)); Note that your want the non-overloaded version of strlen!

Memcache是一個鍵/值存儲,因此不“知道”更“復雜”的對象。模塊所做的是將值序列化並將其存儲為字符串。因此,total size = strlen(serialize($value));注意,您想要的是非重載的strlen版本!

#2


0  

This doesn't directly answer your question, however you can change the 1MB limit to something larger if needed.

這並不能直接回答您的問題,但是如果需要,您可以將1MB的限制更改為更大的。

See: http://linux.die.net/man/1/memcached

參見:http://linux.die.net/man/1/memcached

-I Override the default size of each slab page. Default is 1mb. Default is 1m, minimum is 1k, max is 128m. Adjusting this value changes the item size limit. Beware that this also increases the number of slabs (use -v to view), and the overal memory usage of memcached.

-我覆蓋了每個面板頁面的默認大小。默認是1 mb。默認值為1m,最小值為1k,最大值為128m。調整此值將更改項目大小限制。注意,這也會增加slabs的數量(使用-v查看),以及memcached的內存使用情況。

You can also enable compression to reduce the size of the value as well. See: http://ca.php.net/manual/en/memcache.setcompressthreshold.php

您還可以啟用壓縮來減少值的大小。參見:http://ca.php.net/manual/en/memcache.setcompressthreshold.php

#3


-1  

Or you try a complicated way strlen(serialize($array)); Or you try the easy way

或者你嘗試一種復雜的方法strlen(serialize($array));或者你試試簡單的方法

$before = memory_get_usage();
$myarray = array(<content>);
$size = memory_get_usage() - $before;

Could not think of any other way sorry

想不出任何其他的方式對不起


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2012/06/12/72f8987de303bd4d114b25ca8905e0f7.html



 
粤ICP备14056181号  © 2014-2021 ITdaan.com