Possible Duplicate:
An efficient way to save an Array and its Keys to a database
Is there maybe an serialize() equivalent which returns binary?
Saving data as strings is inefficient in both ways: inefficient in a manner of performance and memory. Is there a function to return the pure data from the RAM and accordingly a function to read it back?
If all you are trying to do is get a more compact representation of the serialized string, e.g., one that uses less space than plain serialize()
, you might just use gzdeflate()
to compress the plain-text output:
$data = gzdeflate(serialize($some_array));
// Store in database...
// To restore the array: Get $data from the database, then:
$array = unserialize(gzinflate($data));
Instead of gzdeflate()
/gzinflate()
, you can also use gzcompress()
/gzuncompress()
, but these produce slightly larger strings as they include additional metadata such as a checksum.
精彩评论