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

High-performance PHP-to-Go IPC bridge for calling Golang net/rpc services from PHP. Works over TCP/Unix sockets or pipes, supports JSON/MsgPack and raw []byte payloads, includes robust error handling, runs on Windows, and has minimal dependencies.

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.
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope