Can we create a GRPC server in PHP instead of NodeJS?

5.3k Views Asked by At

I'm new to GRPC I read the quickstart guide and PHP basics. But I see lot all are using NodeJS to run the server side for grpc. But what I wanted to achieve is use PHP on both ends of grpc and create Server + Client in PHP only.

So it's like Client will send the informtation to server and Server will process the information realtime.

I have checked the test case files ServerTest.php code is below

class ServerTest extends PHPUnit_Framework_TestCase
{
    public function setUp()
    {
    }

    public function tearDown()
    {
    }

    /**
     * @expectedException InvalidArgumentException
     */
    public function testInvalidConstructor()
    {
        $server = new Grpc\Server('invalid_host');
    }

    /**
     * @expectedException InvalidArgumentException
     */
    public function testInvalidAddHttp2Port()
    {
        $this->server = new Grpc\Server([]);
        $this->port = $this->server->addHttp2Port(['0.0.0.0:0']);
    }

    /**
     * @expectedException InvalidArgumentException
     */
    public function testInvalidAddSecureHttp2Port()
    {
        $this->server = new Grpc\Server([]);
        $this->port = $this->server->addSecureHttp2Port(['0.0.0.0:0']);
    }
}

I'm not sure if this is possible any help would be highly appriciated:

thanks

6

There are 6 best solutions below

0
On

https://roadrunner.dev/ is an application server for PHP that can allow you to achieve this. I took some notes recently while setting it up and published those over there: https://dev.to/khepin/building-a-grpc-server-in-php-3bgc . Hope that helps though the answer comes a bit later after the question.

0
On

as "Eric G" said currently php server not supported in gRPC. here it is from the Official gRPC website:

Note that currently you can only create clients in PHP for gRPC services - you can find out how to create gRPC servers in our other tutorials, e.g. Node.js.

you can use gRPC community projects like this: https://github.com/spiral/php-grpc

hope this helps

1
On

I'm not sure if this is possible

Read description of gRPC - gRPC is a language neutral and platform neutral

So yes, you can. gRPC PHP tutorial

0
On

You can use gRPC PHP clients to connect to servers written in Node, Java, Python, or a number of other supported languages, but currently gRPC does not support writing PHP servers. The gRPC PHP tutorial describes how to set up a client.

There have been some discussions about implementing gRPC servers in PHP, e.g., the gRPC to FastCGI bridge mentioned on the grpc-io mailing list, but currently this is not supported in gRPC.

0
On

roadrunner may help. It's a golang frontend server with php worker pool.

0
On

what about this, The php grpc server framework with protobuf.

https://github.com/hetao29/php-grpc-server-protobuf