Overview
Workflows serialize data for storage in the database, enabling replay and recovery. The package provides flexible serialization strategies that handle complex PHP objects, closures, and Eloquent models.Default Serializer
By default, the package uses theY serializer, a custom encoding scheme optimized for database storage.
Configuration:
Available Serializers
Y Serializer
Custom encoding that escapes null bytes for safe database storage. Location:src/Serializers/Y.php
How it works (from src/Serializers/Y.php:23-37):
- Default choice for most applications
- Storing in databases with encoding constraints
- Performance is important (fast encoding/decoding)
Base64 Serializer
Base64 encoding for maximum compatibility. Location:src/Serializers/Base64.php
How it works (from src/Serializers/Base64.php:23-31):
- Storing in systems with strict character set requirements
- Debugging (human-readable encoding)
- Transmitting over text-only channels
- ~33% larger storage size
- Slower encoding/decoding
- Safe for any storage medium
Serializer Interface
All serializers implementSerializerInterface (from src/Serializers/SerializerInterface.php:8-16):
What Gets Serialized
The serialization system handles:Primitive Types
Eloquent Models
Fromsrc/Serializers/AbstractSerializer.php:31-48, models are automatically serialized:
Closures
Fromsrc/Serializers/AbstractSerializer.php:60-75, closures are wrapped in SerializableClosure:
Collections
DateTime Objects
Complex Nested Data
Serialization Process
Fromsrc/Serializers/AbstractSerializer.php:60-75, the full serialization flow:
Deserialization Process
Fromsrc/Serializers/AbstractSerializer.php:67-75, unserialization:
Automatic Serialization
TheSerializer facade (from src/Serializers/Serializer.php:8-25) automatically detects the format:
Custom Serializer
Create a custom serializer:Model Serialization Details
Fromsrc/Serializers/AbstractSerializer.php:31-58, Eloquent models:
Serialization
What’s Stored
For an Eloquent model:Restoration
On unserialization, models are fresh instances from the database:Serialization Limits
Unserializable Types
Some types cannot be serialized:Testing Serializability
Fromsrc/Serializers/AbstractSerializer.php:21-29:
Storage Considerations
Database Column Type
Ensure sufficient storage:Size Optimization
Security
Fromsrc/Serializers/AbstractSerializer.php:62,69, closures are encrypted:
APP_KEY to prevent tampering.
Best Practices
Minimize Serialized Data
Minimize Serialized Data
Store minimal data in workflow state:
Use Model References
Use Model References
Let the serializer handle models:
Avoid External References in Closures
Avoid External References in Closures
Test Serialization
Test Serialization
Debugging Serialization Issues
Performance Considerations
Serialization Speed
Storage Size
Related Topics
- Durability - How workflows are stored
- Activities - Activity data handling
- Error Handling - Serializing exceptions
- Configuration - Serializer configuration