Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Goridge Laravel Package

spiral/goridge

Spiral GoRidge is a high-performance PHP↔Go RPC bridge used by RoadRunner. It provides fast inter-process communication via relay transports (pipes, TCP, sockets) with a compact binary protocol, enabling scalable PHP apps and background workers.

View on GitHub
Deep Wiki
Context7

Getting Started

  • Core concept: Goridge enables high-speed communication between PHP and Go processes using shared memory, sockets, or streams—no HTTP overhead.
  • First use case: Run a PHP script that calls a Go service for computationally heavy tasks (e.g., image processing, cryptographic ops, or JSON parsing at scale).
  • Installation: composer require spiral/goridge
  • Quick start:
    1. Start a Go worker (e.g., go run worker.go)
    2. In PHP, instantiate Goridge\RPC\RPC::createWithOptions('tcp://127.0.0.1:6001') (or UnixSocket, RelaySocket, Stream for local use)
    3. Call Go methods synchronously with $rpc->call('Service.Method', $payload)
  • Look first in the docs at: The Basic Usage and Transports sections—UnixSocket is recommended for local development for lowest latency.

Implementation Patterns

  • Worker模式 (Worker Pattern): Use Go as a long-lived worker process handling parallel requests via Goridge—ideal for queue consumers (e.g., processing jobs from RoadRunner or Symfony Messenger).
  • Proxy/Adapter pattern: Wrap Goridge RPC calls in a PHP service class to abstract transport and provide typed interfaces:
    class ImageProcessor {
        private $rpc;
        public function __construct() {
            $this->rpc = RPC::createUnix('/tmp/goridge.sock');
        }
        public function resize(string $path, int $width): string {
            return $this->rpc->call('Image.Resize', [$path, $width]);
        }
    }
    
  • Bidirectional RPC: Use Goridge\Relay for two-way communication—PHP calls Go, and Go can push data back (e.g., streaming logs or progress updates).
  • Integration with RoadRunner: Pair with Spiral RoadRunner to serve HTTP workers in Go while handling PHP microservices via Goridge—common in high-throughput APIs.
  • Debugging workflows: Use Stream transport (goridge://tmp/goridge.stream) for local debugging; logs and stack traces are easier to trace than with binary socket protocols.

Gotchas and Tips

  • Binary safety matters: Goridge uses MessagePack for serialization—ensure Go structs have exported fields (json tags won’t auto-match). Use goridge-go’s msgpack tags if interoperating with Go clients.
  • Error handling: PHP throws Goridge\RPC\Exceptions\RemoteException on Go-side panics; always wrap call() in try/catch and inspect $e->getPayload() for Go stack traces.
  • Performance tuning:
    • Prefer UnixSocket over TCP for same-host communication (5–10x faster).
    • For high concurrency, set options=['frames' => 1024] to reduce syscall overhead.
  • Garbage collection: Goridge keeps memory-mapped buffers—enable options=['shared' => false] if memory leaks appear in long-running CLI workers (PHP GC won’t free them otherwise).
  • Testing: Use Relay + stream_get_contents() to mock Go responses in unit tests without spawning processes.
  • Extension point: Implement Goridge\TransportInterface for custom transports (e.g., Kafka, AMQP) by wrapping their pub/sub semantics around Goridge’s frame-based protocol.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport