amphp/serialization
AMPHP serialization tools for IPC and storage in PHP. Provides a Serializer interface with JSON, native PHP serialize/unserialize, and passthrough implementations, plus optional payload compression via a wrapping serializer.
json_encode or serialize() cannot handle. Critical for projects leveraging amphp/parallel, amphp/byte-stream, or custom IPC.NativeSerializer for trusted internal communication (e.g., worker-to-worker) where object fidelity is required. Avoid for untrusted data due to unserialize() risks.amphp/redis, amphp/parallel) and requires:
json_encode cannot handle.#[Override] for custom logic).json_encode fails on circular references, serialize() lacks compression).json_encode, serialize(), cache drivers) are more mature, secure, and actively maintained."This package optimizes high-throughput IPC in our AMPHP-based microservices by compressing payloads and preserving complex PHP objects, reducing latency in worker pools. However, it’s a niche tool with no Laravel integration and stagnant development. We’d only adopt it if we’re fully committed to AMPHP, and even then, we’d need to isolate its use to avoid technical debt. The PHP 7.4 requirement also conflicts with our Laravel 9+ roadmap, so this is not a silver bullet—just a tactical fix for specific AMPHP workflows."
*"Pros:
CompressingSerializer) can reduce IPC payloads by 30–50% for large objects (benchmarks required).Cons:
NativeSerializer.unserialize() is unsafe—only use for internal IPC.Recommendation:
*"When to Use:
When to Avoid:
json_encode instead).Quick Start:
// Compress native serialization for IPC
$serializer = new CompressingSerializer(new NativeSerializer());
$payload = $serializer->serialize([
'task' => $closure,
'data' => $resource
]);
socket_write($socket, $payload);
Warning: This is not a general-purpose serializer. Stick to Laravel’s json_encode for everything else."*
How can I help you explore Laravel packages today?