amphp/serialization
AMPHP serialization tools for IPC and data storage in concurrent PHP apps. Provides a Serializer interface with JSON, native PHP, and passthrough serializers, plus optional payload compression via a wrapping serializer.
Architecture fit:
The amphp/serialization package is optimized for AMPHP’s event-driven, fiber-based concurrency model, making it a poor fit for Laravel’s synchronous request/response architecture. Its Serializer interface is low-level and generic, lacking Laravel-specific optimizations (e.g., Eloquent relationships, cache drivers, or API response handling). The package assumes IPC or data storage use cases, not Laravel’s high-level abstractions like queues, caching, or HTTP responses. Key misalignment:
json_encode, serialize in cache drivers).Integration feasibility:
amphp/byte-stream, amphp/redis, or custom IPC.json_encode in API responses or serialize in cache). No drop-in replacements exist for:
Illuminate\Bus\Queueable).Illuminate\Cache\Repository).Technical risk:
NativeSerializer uses PHP’s native unserialize(), which is unsafe for untrusted data (e.g., user input in IPC). No documented mitigations (e.g., whitelisting, sandboxing).#[Override] may not work with Laravel’s attributes (e.g., #[Cacheable]). No PHP 8.x support confirmed, risking serialization failures during upgrades.SerializationException for unsupported types).@mathroc) has no Laravel experience, limiting future support.CompressingSerializer) may not benefit small payloads (e.g., API responses) and adds CPU overhead.Key questions:
json_encode, Redis::compress(), serialize) or existing packages (e.g., spatie/array-to-object)?NativeSerializer be isolated from untrusted data (e.g., user input in IPC)? Are there whitelists or validation layers?#[Override] work with Laravel’s attributes (e.g., #[Cacheable])? If not, what’s the upgrade cost to support them?SerializationException be caught and retried in async contexts (e.g., queue workers, cache)?JsonSerializer)?json_encode, serialize) or existing packages (e.g., spatie/laravel-activitylog for serialization) achieve the same goals with lower risk?Stack fit:
amphp/redis pub/sub) where:
Migration path:
amphp/redis interactions.serialize/unserialize in workers).
serialize($data) → new NativeSerializer()->serialize($data).CompressingSerializer) for large payloads.
$serializer = new CompressingSerializer(new NativeSerializer());.json_encode in API responses).SerializationException (e.g., retry with JsonSerializer).JsonSerializer to ensure compatibility with:
NativeSerializer only for trusted internal IPC (e.g., worker-to-worker comms).amphp/byte-stream) unless explicitly needed.replace or conflict to prevent accidental upgrades.Critical blockers:
belongsTo, hasMany).JsonSerializer may fail).Illuminate\Bus\Queueable).NativeSerializer cannot be used for untrusted data—requires architectural isolation (e.g., separate IPC channels).Maintenance:
SerializationException handling, PHP 8.x support) must be maintained in-house.amphp/byte-stream), adding unnecessary complexity for non-AMPHP projects.Support:
How can I help you explore Laravel packages today?