golang 代码:
package main
import (
"fmt"
"net"
"net/rpc"
"github.com/spiral/goridge/v2"
)
type App struct{}
func (*App) Hi(name string, r *string) error {
*r = fmt.Sprintf("hello %s!", name)
return nil
}
type Ceshi struct{}
func (*Ceshi) Demo(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))
rpc.Register(new(Ceshi))
for {
conn, err := ln.Accept()
if err != nil {
continue
}
go rpc.ServeCodec(goridge.NewCodec(conn))
}
}
/****************************************************************/
php代码:
use Spiral\Goridge\RPC;
use Spiral\Goridge\Relay;文章来源:https://uudwc.com/A/mJrdv
$rpc = new RPC(Relay::create('tcp://127.0.0.1:6001'));
echo $rpc->call("Ceshi.Demo", "ceshi");文章来源地址https://uudwc.com/A/mJrdv