0

Going for space savings here. I have an object that I need to serialize for each row.

In theory, it needs to consist of 168 16b unsigned integers (even though there's no explicit typing in php), that should be worth 336 bytes.

If I go for the serialize() function that creates strings though, the size is up to 2349 bytes.

Is there a binary kind of serializer for php?

user81993
  • 6,167
  • 6
  • 32
  • 64

1 Answers1

0

Store the data in a plain and simple array. Then pack it:

$len = count($arr);
$data = pack("S$len", ...$arr); // requires PHP5.6+

To get the array back you want to unpack()it:

$arr = unpack("S$len", $data);

Mind you that you need to keep the $len variable along the $data block.

More about it here.

Community
  • 1
  • 1
pid
  • 11,472
  • 6
  • 34
  • 63