Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .claude/settings.local.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"permissions": {
"allow": [
"Bash(tail:*)",
"Bash(go test:*)",
"Bash(golangci-lint run:*)",
"Bash(head:*)",
"Bash(gh api:*)",
"Bash(ls:*)",
"Bash(which yamllint:*)",
"Bash(go run:*)",
"WebFetch(domain:github.com)",
"WebFetch(domain:raw.githubusercontent.com)",
"Bash(php:*)",
"WebFetch(domain:packagist.org)",
"Bash(git:*)",
"WebFetch(domain:api.github.com)",
"WebSearch"
]
}
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
1 change: 0 additions & 1 deletion .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ jobs:
mkdir ./coverage-ci
go test -v -race -cover -tags=debug -coverpkg=./... -coverprofile=./coverage-ci/frame.out -covermode=atomic ./pkg/frame
go test -v -race -cover -tags=debug -coverpkg=./... -coverprofile=./coverage-ci/pipe.out -covermode=atomic ./pkg/pipe
go test -v -race -cover -tags=debug -coverpkg=./... -coverprofile=./coverage-ci/rpc.out -covermode=atomic ./pkg/rpc
go test -v -race -cover -tags=debug -coverpkg=./... -coverprofile=./coverage-ci/socket.out -covermode=atomic ./pkg/socket
go test -v -race -cover -tags=debug -coverpkg=./... -coverprofile=./coverage-ci/internal.out -covermode=atomic ./internal
- name: Run fuzz tests
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,5 @@ jobs:
run: |
go test -v -race -cover -tags=debug -coverpkg=./... -covermode=atomic ./pkg/frame
go test -v -race -cover -tags=debug -coverpkg=./... -covermode=atomic ./pkg/pipe
go test -v -race -cover -tags=debug -coverpkg=./... -covermode=atomic ./pkg/rpc
go test -v -race -cover -tags=debug -coverpkg=./... -covermode=atomic ./pkg/socket
go test -v -race -cover -tags=debug -coverpkg=./... -covermode=atomic ./internal
1 change: 0 additions & 1 deletion .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,5 @@ jobs:
run: |
go test -v -race -tags=debug ./pkg/frame
go test -v -race -tags=debug ./pkg/pipe
go test -v -race -tags=debug ./pkg/rpc
go test -v -race -tags=debug ./pkg/socket
go test -v -race -tags=debug ./internal
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ test:
go test -v -race -cover -tags=debug ./internal
go test -v -race -cover -tags=debug ./pkg/frame
go test -v -race -cover -tags=debug ./pkg/pipe
go test -v -race -cover -tags=debug ./pkg/rpc
go test -v -race -cover -tags=debug ./pkg/socket

.PHONY: fuzz
Expand Down
75 changes: 44 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
High-performance PHP-to-Golang IPC bridge
High-performance PHP-to-Golang IPC transport
=================================================
[![GoDoc](https://godoc.org/github.com/roadrunner-server/goridge/v4?status.svg)](https://godoc.org/github.com/roadrunner-server/goridge/v4)
![Linux](https://github.com/roadrunner-server/goridge/workflows/Linux/badge.svg)
Expand All @@ -10,8 +10,7 @@ High-performance PHP-to-Golang IPC bridge

<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 a minimal footprint, structures and `[]byte` support.
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](https://github.com/roadrunner-php/goridge)

<br/>
Expand All @@ -21,65 +20,79 @@ See https://github.com/roadrunner-server/roadrunner - High-performance PHP appli
Features
--------

- no external dependencies or services, drop-in (64bit PHP version required)
- no external dependencies, drop-in (64bit PHP required for the PHP side)
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
- low message footprint (12 bytes over any binary payload), binary error detection
- CRC32 header verification
- 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
- 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
- unix sockets powered (also on Windows)
- works on Windows (named pipes, Unix-domain sockets via AF_UNIX)

Installation
------------

```go
GO111MODULE=on go get github.com/roadrunner-server/goridge/v4
```bash
go get github.com/roadrunner-server/goridge/v4
```

### Sample of usage
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated

A minimal echo server using the socket relay:

```go
package main

import (
"fmt"
"log"
"net"
"net/rpc"

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

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")
ln, err := net.Listen("tcp", "127.0.0.1:6001")
if err != nil {
panic(err)
log.Fatal(err)
}

_ = rpc.Register(new(App))

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

out := frame.NewFrame()
out.WriteVersion(out.Header(), frame.Version1)
out.WriteFlags(out.Header(), frame.CodecRaw)
out.WritePayload(in.Payload())
out.WritePayloadLen(out.Header(), uint32(len(in.Payload())))
out.WriteCRC(out.Header())

Comment on lines +84 to +90
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
-------

Expand Down
136 changes: 0 additions & 136 deletions benchmarks/main.go

This file was deleted.

3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ module github.com/roadrunner-server/goridge/v4
go 1.26

require (
github.com/roadrunner-server/errors v1.4.1
github.com/roadrunner-server/errors v1.5.0
github.com/stretchr/testify v1.11.1
google.golang.org/protobuf v1.36.11
)

require (
Expand Down
8 changes: 2 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0=
github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk=
Expand All @@ -12,15 +10,13 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/roadrunner-server/errors v1.4.1 h1:LKNeaCGiwd3t8IaL840ZNF3UA9yDQlpvHnKddnh0YRQ=
github.com/roadrunner-server/errors v1.4.1/go.mod h1:qeffnIKG0e4j1dzGpa+OGY5VKSfMphizvqWIw8s2lAo=
github.com/roadrunner-server/errors v1.5.0 h1:unG7LKIZrSzkCCF3YLRLA5VyqE0KKomofXVJUXJe00g=
github.com/roadrunner-server/errors v1.5.0/go.mod h1:g9fo/T2C13cWRDR9PW1r0ZAOSQfNhWAZawyfkGiaHuI=
github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE=
google.golang.org/protobuf v1.36.11/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
Expand Down
Loading
Loading