goridge

module
v4.0.0-beta.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 9, 2026 License: MIT

README

High-performance PHP-to-Golang IPC transport

GoDoc Linux macOS Windows Go Report Card Codecov

PHPClasses Innovation Award

Goridge is a binary frame protocol with pipe and socket transports for inter-process communication between PHP and Go (or between any two processes that speak the goridge frame format). It exposes a 12-byte CRC-checked framing header, a small Relay interface, and ready-made pipe and TCP/Unix-socket implementations. PHP source code can be found in this repository: goridge-php


See https://github.com/roadrunner-server/roadrunner - High-performance PHP application server, load-balancer and process manager written in Golang

Features

  • no external dependencies, drop-in (64-bit PHP required for the PHP side)
  • low message footprint (12 bytes over any binary payload), binary error detection
  • CRC32 header verification
  • sockets over TCP or Unix domain, standard pipes
  • standalone protocol usage; bring your own RPC layer or none at all
  • structured data transfer (json / msgpack / proto / gob / raw via codec flags)
  • []byte transfer, including large payloads
  • service, message and transport level error handling
  • hackable
  • works on Windows (named pipes, Unix-domain sockets via AF_UNIX)

Installation

go get github.com/roadrunner-server/goridge/v4

Sample usage

A minimal echo server using the socket relay:

package main

import (
	"log"
	"net"

	"github.com/roadrunner-server/goridge/v4/pkg/frame"
	"github.com/roadrunner-server/goridge/v4/pkg/socket"
)

func main() {
	ln, err := net.Listen("tcp", "127.0.0.1:6001")
	if err != nil {
		log.Fatal(err)
	}
	for {
		conn, err := ln.Accept()
		if err != nil {
			log.Printf("accept: %v", err)
			return
		}
		go serve(conn)
	}
}

func serve(conn net.Conn) {
	relay := socket.NewSocketRelay(conn)
	defer func() { _ = relay.Close() }()

	for {
		in := frame.NewFrame()
		if err := relay.Receive(in); err != nil {
			return
		}

		// Mirror the incoming header so the response preserves the client's
		// version, codec and any options/stream bits — a faithful echo.
		out := frame.NewFrame()
		out.WriteVersion(out.Header(), in.ReadVersion(in.Header()))
		out.WriteFlags(out.Header(), in.ReadFlags())
		out.WritePayload(in.Payload())
		out.WritePayloadLen(out.Header(), uint32(len(in.Payload())))
		out.WriteCRC(out.Header())

		if err := relay.Send(out); err != nil {
			return
		}
	}
}

For the pipe-based variant, swap socket.NewSocketRelay(conn) for pipe.NewPipeRelay(in, out) where in is an io.ReadCloser and out is an io.WriteCloser — typically os.Stdin/os.Stdout on a child process.

License

The MIT License (MIT). Please see LICENSE for more information.

Directories

Path Synopsis
Package internal contains shared utilities used by the relay implementations: tiered buffer pooling (1 MB / 5 MB / 10 MB) and the common frame-reception routine ReceiveFrame.
Package internal contains shared utilities used by the relay implementations: tiered buffer pooling (1 MB / 5 MB / 10 MB) and the common frame-reception routine ReceiveFrame.
pkg
frame
Package frame implements a binary frame protocol for inter-process communication.
Package frame implements a binary frame protocol for inter-process communication.
pipe
Package pipe provides a pipe-based [relay.Relay] implementation that communicates with a child process over standard streams (STDIN/STDOUT).
Package pipe provides a pipe-based [relay.Relay] implementation that communicates with a child process over standard streams (STDIN/STDOUT).
relay
Package relay defines the Relay interface for frame-based inter-process communication.
Package relay defines the Relay interface for frame-based inter-process communication.
socket
Package socket provides a socket-based [relay.Relay] implementation for frame transport over TCP and Unix domain connections.
Package socket provides a socket-based [relay.Relay] implementation for frame transport over TCP and Unix domain connections.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL