hello,
I heard that Swoole is doing PHP gRPC Server support normally. Is there any plan for this? If so, when is it expected?
thank you !
grpc-client has released, the server is on the way (next version).
@twose When is the next version expected to be released?
In fact, the current version has already supported gRPC on HTTP2, but more details haven't completed yet.
And we need to write a server side code generator. (use PHP, not swoole)
<?php
use Helloworld\HelloReply;
use Helloworld\HelloRequest;
require __DIR__ . '/../../../vendor/autoload.php';
require __DIR__ . '/../../include/functions.php';
$http = new swoole_http_server('0.0.0.0', 50051, SWOOLE_BASE);
$http->set([
'log_level' => SWOOLE_LOG_INFO,
'trace_flags' => 0,
'worker_num' => 1,
'open_http2_protocol' => true
]);
$http->on('workerStart', function (swoole_http_server $server) {
echo "nghttp -v http://127.0.0.1:{$server->port}\n";
});
$http->on('request', function (swoole_http_request $request, swoole_http_response $response) use ($http) {
/**@var $request_message HelloRequest */
$request_message = Grpc\Parser::deserializeMessage([HelloRequest::class, null], $request->rawcontent());
if ($request_message) {
$response_message = new HelloReply();
$response_message->setMessage('Hello ' . $request_message->getName());
$response->header('content-type', 'application/grpc');
$response->header('trailer','grpc-status, grpc-message');
$headers = [
"grpc-status" => "0",
"grpc-message" => ""
];
foreach ($headers as $header_name => $header_value) {
$response->trailer($header_name, $header_value);
}
$response->end(Grpc\Parser::serializeMessage($response_message));
} else {
$response->end('failed');
}
});
$http->start();
<?php
use Helloworld\GreeterClient;
use Helloworld\HelloRequest;
require __DIR__ . '/../../vendor/autoload.php';
$name = !empty($argv[1]) ? $argv[1] : 'Swoole';
go(function () use ($name) {
$greeterClient = new GreeterClient('127.0.0.1:50051');
$greeterClient->start();
$request = new HelloRequest();
$request->setName($name);
list($reply, $status) = $greeterClient->SayHello($request);
$message = $reply->getMessage();
echo "{$message}\n";
$greeterClient->close();
});
@twose I heard that you are developing gRPC Server with PHP. Is this the next version? Really exciting.
In addition, it is a bit cumbersome to use Swoole directly to do gRPC Server, and there is no complete code framework?
@EDDYCJY 我有点看不懂你的英文, 能用中文沟通吗?
@twose 非常抱歉,是我后面把问题搞复杂了
现在主要就想请教 Swoole 开发组,在开发的基于 PHP 的 gRPC Server 大概什么时候释出?
是否有较具体点的时间,因为我公司这边在观望和等待
感谢
@EDDYCJY
https://github.com/swoole/grpc-client
example中包含了服务端示例, 客户端已经给出完整的实现, 可以开箱即用, 服务端底层已经支持HTTP2, 使用时需要自己实现业务框架, 如路由等.
@twose 前面不是说有在实现基于 PHP 的 gRPC 服务端吗 🤔
example 里的是基于 Swoole 的 gRPC 服务端
@EDDYCJY
https://github.com/swoole/grpc-client/blob/master/examples/grpc/greeter_server.php
Grpc的本质就是HTTP2+Protobuf, 底层只负责实现HTTP2, 已经提供了全套的协程客户端, 服务端需要和框架一起写, 已经提供了简单实现的demo.
你要的东西并不是Swoole这个网络引擎应该提供的, 你可能需要类似Tars或者Swoole的企业级服务框架这样的东西, 这些内容不在这个issue的讨论范围内.
@twose 了解,感谢您的解惑
Hi folks, what is the current status?
I was planning to add this on Siler, but if Swoole officially supports this would be way more awesome.
@leocavalcante Http2 server is available basically, Http2 client implements RFC more completely, but both of these are not the main content of our work...
@twose thank you!
Most helpful comment
@EDDYCJY 我有点看不懂你的英文, 能用中文沟通吗?