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.
CompressingSerializer can significantly reduce payload sizes for AMPHP-based IPC (e.g., Unix sockets, shared memory), improving network and storage efficiency.amphp/redis, amphp/parallel) while preserving serialization logic. Avoids rewriting custom serialization logic during upgrades.json_encode, serialize) are insufficient due to lack of compression or object fidelity (e.g., closures, resources).NativeSerializer for trusted internal IPC (e.g., worker-to-worker communication) where object preservation is required. Never use for untrusted data (e.g., user input) 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?