PHP code example of highperapp / grpc

1. Go to this page and download the library: Download highperapp/grpc library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

highperapp / grpc example snippets



use HighPerApp\HighPer\GRPC\GrpcServerFactory;
use HighPerApp\HighPer\GRPC\Examples\GreeterService;

// Configuration
$config = [
    'host' => '0.0.0.0',
    'port' => 9090,
    'worker_processes' => 4,
    'parallel_workers' => 2,
    'circuit_breaker' => ['enabled' => true],
    'retry' => ['enabled' => true],
    'engine' => ['rust_acceleration' => true]
];

// Create server
$factory = new GrpcServerFactory($config);
$server = $factory->createHighPerformanceServer();

// Register service
$server->registerService(new GreeterService());

// Start server
$server->start();


use HighPerApp\HighPer\GRPC\ServiceProvider\GrpcServiceProvider;

// In your framework's service container
$grpcProvider = new GrpcServiceProvider($container, $config);
$grpcProvider->register();
$grpcProvider->boot();

// Register services
$grpcProvider->registerService(YourService::class);

// Get server
$server = $grpcProvider->getServer();

$config = [
    'host' => '0.0.0.0',
    'port' => 9090,
    'worker_processes' => 4,
    'parallel_workers' => 2,
    'circuit_breaker' => [
        'enabled' => true,
        'failure_threshold' => 5,
        'timeout_seconds' => 60
    ],
    'retry' => [
        'enabled' => true,
        'max_attempts' => 3,
        'base_delay_ms' => 100
    ],
    'engine' => [
        'rust_acceleration' => true,
        'fallback_to_php' => true
    ]
];