skip to Main Content

I put these 3 parameters:

grpc.keepalive_time_ms=7200000
grpc.keepalive_timeout_ms=200000
grpc.keepalive_permit_without_calls=1

in /etc/php/8.1/apache2/conf.d/20-grpc.ini, /etc/php/8.1/apache2/conf.d/custom-php.ini, /etc/php/8.1/cli/conf.d/20-grpc.ini and /etc/php/8.1/cli/conf.d/custom-php.ini. Then I restart webserver (whole Docker container) and list grpc config with php -i | grep grpc and they are missing from the output:

/etc/php/8.1/cli/conf.d/20-grpc.ini,
grpc
grpc support => enabled
grpc module version => 1.59.1
grpc.enable_fork_support => 0 => 0
grpc.grpc_trace => all,-timer_check => all,-timer_check
grpc.grpc_verbosity => debug => debug
grpc.log_filename => /var/log/grpc.log => /var/log/grpc.log
grpc.poll_strategy => no value => no value

I tested it with PHP 8.1, gRPC extension 1.45.0 and 1.59.1.
What am I doing wrong?

2

Answers


  1. Chosen as BEST ANSWER

    It turns out these parameters dont belong to PHP .ini config files. They need to be in PHP code, passed as options array into gRPC client class constructor.

    $options['grpc.keepalive_time_ms'] = 7200000;
    $options['grpc.keepalive_timeout_ms'] = 200000;    
    $options['grpc.keepalive_permit_without_calls'] = 1;
    
    $client = new Client('host:port', $options);
    

  2. It seems that you are trying to set the gRPC keepalive parameters in PHP, but they are not taking effect. There are a few possible reasons for this:

    • The gRPC keepalive parameters are only available for the gRPC C extension, not the gRPC PHP extension¹. If you are using the gRPC PHP extension, you will not be able to use these parameters. You can check which extension you are using by running php -m | grep grpc and see if it returns grpc or grpc_c.
    • The gRPC keepalive parameters are only applicable for the client side, not the server side². If you are trying to set them on the server side, they will be ignored. You can only set them on the client side when you create a new gRPC channel, for example:
    <?php
    // Create a new gRPC channel with keepalive parameters
    $channel = new GrpcChannel('localhost:50051', [
        'grpc.keepalive_time_ms' => 7200000,
        'grpc.keepalive_timeout_ms' => 200000,
        'grpc.keepalive_permit_without_calls' => 1,
    ]);
    
    // Create a new stub for the service
    $stub = new HelloworldGreeterClient($channel);
    
    // Make a unary call
    $request = new HelloworldHelloRequest();
    $request->setName('world');
    list($reply, $status) = $stub->SayHello($request)->wait();
    $message = $reply->getMessage();
    echo "Greeting: $messagen";
    
    • The gRPC keepalive parameters are not supported by some proxies or load balancers that may terminate idle connections². If you are using a proxy or a load balancer between your client and server, you may need to configure them to allow HTTP/2 PING frames or increase their idle timeout.
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search