PHP code example of bearsunday / thrift

1. Go to this page and download the library: Download bearsunday/thrift 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/ */

    

bearsunday / thrift example snippets


(new ServerBootstrap)(new Config(
    appName: 'MyVendor\MyApp',
    hostname: '127.0.0.1',
    port: 9090,
    appDir: dirname(__DIR__) . '/path/to/app',
    context: 'prod-app',
    server: Engine::Swoole
))

protected function configure(): void
{
    // Binding thirft app to a host called "sekai"
    $this->override(new ImportThriftAppModule([
        new ThriftApp('sekai', '127.0.0.1', '9090')
    ]));
}

echo $resource->get('page://self/?name=Sekai');  // "greeting": "Konichiwa Sekai" from local app
echo $resource->get('page://sekai/?name=World'); // "greeting": "Hello World" from remote(127.0.0.1:9090) app
// echo $resource->get('/?name=World'); // "greeting": "Hello World" from remote(127.0.0.1:9090) app

$method = 'get';
$uri = '/user?id=1';

$invoke = new ResourceInvoke($host, $port);
$response = $invoke($method, $uri);

assert($response instanceof ResourceResponse);
printf("Response Code: %s\n", $response->code);
printf("Response Headers: %s\n", json_encode($response->headers));
printf("Raw Response JsonValue: : %s\n", $response->jsonValue);
printf("Response View: %s\n", $response->view);