golang代码: go get github.com/roadrunner-server/goridge/v3
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() {
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代码:
use Spiral\Goridge\RPC\RPC;
use Spiral\Goridge\Relay;
$rpc = new RPC(Relay::create('tcp://127.0.0.1:6001'));
echo $rpc->call("App.Hi", "ceshi");