Home » Php » php – What is the php_binary serialization handler?

php – What is the php_binary serialization handler?

Posted by: admin July 12, 2020 Leave a comment


When I do phpinfo() or php -i from the CLI, I get the following output:


Registered save handlers => files user sqlite memcached
Registered serializer handlers => php php_binary wddx

I was not aware that PHP serialization supported a binary format, and there does not appear to be anything in the documentation about it.

I was going to use igbinary for session serialization to a memcached server, so I’m wondering how php_binary compares.

How to&Answers:

The igbinary PHP extension does offer a new session serialize/deserialize handler that differs from PHP’s own implementations, namely php and php_binary.

To answer your question: These handlers do not compare at all, they are totally different. The differences igbinary introduces are documented within the projects readme.

I assume you’re asking the question because you found the word binary within the two: igbinary and php_binary. However that’s not saying much. Compare the php with the php_binary handler first:

The php_binary session serialize/deserialize handler is nearly identical with the default php handler. They differ only how the variable names that are within the session are encoded.

php_binary will prefix all session variable names with the binary length of the name. While with php each variable name has a suffix of the | character (\x7C, decimal 124). From what I know, the serialization of the variable’s values does not differ at all.

So the serialization of values is identical between the php and php_binary handler.

So next to the little difference in pre-/suffix of session variable names, the question actually asks about how does igbinary compare with php serialization (which is used in the session data). Those differences are outlined in the igbinary readme. It fairly well describes what’s done and why.

If you like to use igbinary serialization as well for serialize/unserialize, the extension offers two replacement functions:

igbinary_serialize and igbinary_unserialize – used like their php cousins.

If you are concerned about some specifics of the differences, please ask.