mateusjunges/avro-serde-php
Avro SerDe library for PHP 7.3+ and 8.0 that implements the Confluent wire format and integrates a cached Schema Registry client, so you can serialize and deserialize Avro messages while keeping schema evolution compatible with downstream consumers.
Install via Composer: composer require mateusjunges/avro-serde-php. As of v3.1.0 the package requires PHP 8.1+, flix-tech/avro-php ^5.1, and (for registry work) mateusjunges/confluent-schema-registry-api — pin that to 9.1.0 or later if you want Guzzle 8 support.
Next, review the README — it provides a minimal Symfony Serializer setup example. The primary entry point is the AvroSerializer class, which integrates with Symfony’s Serializer component (pulled into Laravel via symfony/serializer). To serialize/deserialize an object, define your schema (JSON file or inline string), load it into an AvroSchema, and pass both the schema and your object to the AvroSerializer. The first common use case is serializing domain objects to Avro binary for Kafka producers or a schema registry.
If you are on Laravel 9/10 with an older PHP constraint, verify your composer.json platform requirement before upgrading — v3.1.0 will not install on PHP 8.0.
schemas/user.avsc) and load them via AvroSchema::loadJsonFile() or use inline schema strings for simple cases.AvroSerializer (and SchemaRegistrySerializer) as singletons in a service provider so the parsed Schema graph and the Guzzle/PSR-18 HTTP client are reused across requests and jobs.AvroSerializer as a normalizer/encoder and tag it appropriately if you are using the full Symfony Serializer; in Laravel, resolve it from the container rather than instantiating per call.SchemaRegistrySerializer to resolve schema IDs dynamically from a remote registry (e.g., Confluent Schema Registry). With v3.1.0 you can now run on Guzzle 8 (guzzlehttp/promises ^3.0) provided the registry client is on 9.1.0+; cache schema lookups using Laravel’s cache repository for performance.public string $name;) and let the serializer handle conversion and validation based on the Avro schema.flix-tech/avro-serde-php changes. If you are still on 8.0, stay on 3.0.x or upgrade the runtime first.guzzlehttp/promises ^3.0 is allowed, but Guzzle 8 compatibility flows through mateusjunges/confluent-schema-registry-api 9.1.0. Upgrading Guzzle without bumping the registry client will leave you with an unresolvable dependency set — bump both together and re-run your HTTP client bindings.AvroNameConverter had implicitly nullable parameters, fixed in v3.1.0. If you forked or subclassed that converter, re-check your signature (?Type $x = null rather than Type $x = null).widmogrod/php-functional ^7.0 is now permitted and flix-tech/avro-php must be ^5.1. Run composer why widmogrod/php-functional after upgrading if you have other packages pinning ^6.x — Composer may resolve to an older avro-serde if constraints conflict.SchemaResolutionException. Use defaults and unions (["null","string"]) for forward/backward compatibility.false to AvroSerializer::encode() for Kafka payloads and true for base64 when debugging or logging.Schema instance. In long-running workers (Horizon, Octane, queue daemons) hold schemas in singletons/static properties and remember the registry client’s connection is also long-lived.#[AvroName]-style hints to work.AvroSerializer::setLogger() to capture resolution failures; messages typically name the expected vs. actual field and type, which is usually enough to locate the schema drift.How can I help you explore Laravel packages today?