package module
Version: v1.0.5 Latest Latest

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

Go to latest
Published: Feb 6, 2021 License: MIT Imports: 8 Imported by: 10


Goridge, high performance PHP-to-Golang net/rpc codec

Latest Stable Version GoDoc License Build Status Scrutinizer Code Quality Coverage Status

Goridge is high performance PHP-to-Golang codec library which works over native PHP sockets and Golang net/rpc package. The library allows you to call Go service methods from PHP with minimal footprint, structures and []byte support.


  • no external dependencies or services, drop-in
  • low message footprint (9 bytes over any binary payload)
  • sockets over TCP or Unix
  • very fast (260k calls per second on Ryzen 1700X over 25 threads)
  • native net/rpc integration, ability to connect to existed application(s)
  • structured data transfer using json
  • []byte transfer, including big payloads
  • service, message and transport level error handling
  • hackable
  • works on Windows


use Spiral\Goridge;
require "vendor/autoload.php";

$rpc = new Goridge\JsonRPC(new Goridge\Connection("", 6001));

echo $rpc->call("App.Hi", "Antony");
package main

import (

type App struct{}

func (s *App) Hi(name string, r *string) error {
	*r = fmt.Sprintf("Hello, %s!", name)
	return nil

func main() {
	ln, err := net.Listen("tcp", ":6001")
	if err != nil {


	for {
		conn, err := ln.Accept()
		if err != nil {
		go rpc.ServeCodec(goridge.NewJSONCodec(conn))
$ go get "github.com/spiral/goridge"

See tests folder for more examples.

Check this libraries in order to find suitable socket manager:




View Source
const (
	KeepConnection  = 0
	CloseConnection = 1
	NoBody          = 16
	RawBody         = 32
	ErrorBody       = 64
View Source
const (
	ChunkSize = 655336


This section is empty.


This section is empty.


type JSONCodec

type JSONCodec struct {
	// contains filtered or unexported fields

A JSONCodec implements ServeCodec using 9 bytes data prefixes and body marshaling via json.

func NewJSONCodec

func NewJSONCodec(conn io.ReadWriteCloser) *JSONCodec

NewJSONCodec initiates new JSONCodec over given connection.

func (*JSONCodec) Close

func (c *JSONCodec) Close() error

Close underlying socket.

func (*JSONCodec) ReadRequestBody

func (c *JSONCodec) ReadRequestBody(out interface{}) error

ReadRequestBody fetches prefixed body payload and automatically unmarshal it as json. RawBody flag will populate []byte lice argument for rpc method.

func (*JSONCodec) ReadRequestHeader

func (c *JSONCodec) ReadRequestHeader(r *rpc.Request) error

ReadRequestHeader request metadata.

func (*JSONCodec) WriteResponse

func (c *JSONCodec) WriteResponse(r *rpc.Response, body interface{}) error

WriteResponse marshaled response, byte slice or error to remote party.

type Prefix

type Prefix []byte

Prefix is always 9 bytes long and contain meta flags and length of next data package.

func (Prefix) Flags

func (p Prefix) Flags() byte

func (Prefix) HasBody

func (p Prefix) HasBody() bool

func (Prefix) SetFlags

func (p Prefix) SetFlags(flags byte)

func (Prefix) SetSize

func (p Prefix) SetSize(size uint64)

func (Prefix) Size

func (p Prefix) Size() uint64


Path Synopsis

Jump to

Keyboard shortcuts

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