PHP code example of lao-liu / laravel-hprose

1. Go to this page and download the library: Download lao-liu/laravel-hprose 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/ */

    

lao-liu / laravel-hprose example snippets


# edit app/config/app.php
#     Laoliu\LaravelHprose\HproseServiceProvider::class,
];

# class,
    'RpcServer'    => Laoliu\LaravelHprose\HproseServerFacade::class,
    'RpcService'   => Laoliu\LaravelHprose\HproseServiceFacade::class,
];

# Laravel config
php artisan vendor:publish --provider="Laoliu\LaravelHprose\HproseServiceProvider"

use RpcClient as Rpc;
$result = Rpc::someServerMethod($params);

Route::any('/api', function() {
    $server = app('RpcServer');
    
    // Hprose support XmlRPC and JsonRPC
    // if want support XmlRpc
    $server->addFilter(new Hprose\Filter\XMLRPC\ServiceFilter());
    // if want support JsonRpc
    $server->addFilter(new Hprose\Filter\JSONRPC\ServiceFilter());
    
    $server->addInstanceMethods(new \App\Services\SomeHprosePublishServices());
    $server->start();
});

# app/Http/Middleware/VerifyCsrfToken.php
[...]
protected $except = [
    'api' // OR 'api*'
];

# edit bootstrap/app.php
$app->register(Laoliu\LaravelHprose\HproseServiceProvider::class);

[...]

class_alias('Laoliu\LaravelHprose\HproseClientFacade', 'RpcClient');
class_alias('Laoliu\LaravelHprose\HproseServerFacade', 'RpcServer');
class_alias('Laoliu\LaravelHprose\HproseServiceFacade', 'RpcService');

return $app;

$rpc = app('RpcClient')->useService('http://hproseServiceUrl/', $async);
$result = $rpc->remoteMethods($params);

Route::any('/api', function() {
    $server = app('RpcServer');
    
    // Hprose support XmlRPC and JsonRPC
    // if want support XmlRpc
    $server->addFilter(new Hprose\Filter\XMLRPC\ServiceFilter());
    // if want support JsonRpc
    $server->addFilter(new Hprose\Filter\JSONRPC\ServiceFilter());
    
    $server->addInstanceMethods(new \App\Services\SomeHprosePublishServices());
    $server->start();
});

# config/hprose.php