/goridge

High-performance PHP-to-Golang RPC bridge which works everywhere

Primary LanguagePHPMIT LicenseMIT

High-performance PHP-to-Golang RPC bridge

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

PHPClasses Innovation Award

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.


Features

  • 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

Examples

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

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

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

import (
	"fmt"
	"github.com/spiral/goridge"
	"net"
	"net/rpc"
)

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 {
		panic(err)
	}

	rpc.Register(new(App))

	for {
		conn, err := ln.Accept()
		if err != nil {
			continue
		}
		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: