Cover of the book Symfony 5: The Fast Track

Symfony 5: The Fast Track is the best book to learn modern Symfony development, from zero to production. +300 pages showcasing Symfony with Docker, APIs, queues & async tasks, Webpack, SPAs, etc.

New in Symfony 4.3: Native PHP Serialization for Messenger

Contributed by
Ryan Weaver
in #29958.

In Symfony 4.2, the Messenger component uses the Serializer component to serialize messages to JSON and then unserialize them. This creates some issues:

  • The default serializer requires you to have getter & setter methods (or public properties) for them to be serialized. This makes it easy for data to disappear.
  • Moreover, the forced getters/setters (and no required constructor arguments) force you to design your message classes around this.

The original reason why we did this was so that we could export "generic JSON", in case we wanted other workers to consume the messages, no matter if they used Symfony, PHP or any other programming language and technology. However, this is not the common use case and it was complicating things unnecessarily.

In Symfony 4.3, we fixed this problem by switching the serialization to a new class called PhpSerializer which uses PHP's native serialize() and unserialize() to serialize messages to a transport.

If you want to keep using the previous JSON serializer (or your own custom serializer service) configure it as follows:

# config/packages/messenger.yaml
            # ID of the service to use to serialize messages
            id: 'messenger.transport.symfony_serializer'
Help the Symfony project!

As with any Open-Source project, contributing code or documentation is the most common way to help, but we also have a wide range of sponsoring opportunities.

New in Symfony 4.3: Native PHP Serialization for Messenger

Tweet this


Is it configurable to make it use igbinary? Ofc all parties involved need igbinary installed.

Glad to see the Messenger component maturing!

Comments are closed.

To ensure that comments stay relevant, they are closed for old posts.