I use https://github.com/roadrunner-php/goridge and https://github.com/roadrunner-server/goridge
.rr.dev.yaml
version: "2.7"
server:
command: "php bin/road-runner-console baldinof:roadrunner:worker"
env:
- APP_RUNTIME: Baldinof\RoadRunnerBundle\Runtime\Runtime
go_worker:
command: "go run main.go"
env:
- GOOS: linux
- GOARCH: amd64
main.go
package main
import (
"fmt"
"net"
"net/rpc"
goridgeRpc "github.com/roadrunner-server/goridge/v3/pkg/rpc"
)
type App struct{}
func (s *App) Hi(name string, r *string) error {
*r = fmt.Sprintf("Hello, %s!", name)
return nil
}
func main() {
fmt.Println("Hello")
ln, err := net.Listen("tcp", ":6001")
if err != nil {
panic(err)
}
_ = rpc.Register(new(App))
for {
conn, err := ln.Accept()
if err != nil {
continue
}
_ = conn
go rpc.ServeCodec(goridgeRpc.NewCodec(conn))
}
}
php code
$tcpRPC = new Goridge\RPC\RPC(Goridge\Relay::create('tcp://127.0.0.1:6001'));
$r = $tcpRPC->call("App.Hi", "Antony");
var_dump(
$r
); echo __METHOD__.':'.__LINE__;die();
run rr
bin/rr-server serve .rr.dev.yaml -d
output
{"level":"debug","ts":1729072653.5290942,"logger":"rpc","msg":"plugin was started","address":"tcp://127.0.0.1:6001","list of the plugins with RPC methods:":["informer","resetter","app"]}
[INFO] RoadRunner server started; version: 2.12.3, buildtime: 2023-02-16T13:08:41+0000
run console php command
"exception" => Spiral\Goridge\RPC\Exception\ServiceException^ {
#message: "Error 'rpc: can't find service App.Hi' on tcp://127.0.0.1:6001"
all this in docker. maybe you need to forward ports somehow. but in general I run the server launch and command inside the container – in different consoles
You need to sign in to view this answers