PHP Classes

File: README.md

Recommend this page to a friend!
  Classes of Wolfy-J   goridge   README.md   Download  
File: README.md
Role: Documentation
Content type: text/markdown
Description: Documentation
Class: goridge
Run Golang code from PHP calling its RPC server
Author: By
Last change: Update README.md
Update README.md
Date: 6 years ago
Size: 2,856 bytes
 

Contents

Class file image Download

High-performance PHP-to-Golang IPC bridge

Latest Stable Version GoDoc Build Status Scrutinizer Code Quality Go Report Card

<img src="https://files.phpclasses.org/graphics/phpclasses/innovation-award-logo.png" height="90px" alt="PHPClasses Innovation Award" align="left"/>

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.

<br/> Goridge relays can be used independently to ensure fast IPC connection between PHP and Go processes.

See RoadRunner - embeddable PHP worker pool library. <br/>

Features

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

Installation

$ go get "github.com/spiral/goridge"
$ composer require spiral/goridge

Example

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

$rpc = new Goridge\RPC(new Goridge\SocketRelay("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, rstring) 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.NewCodec(conn))
	}
}

Check this libraries in order to find suitable socket manager: * https://github.com/fatih/pool * https://github.com/hashicorp/yamux

License

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