{"id":35190325,"url":"https://github.com/overlu/laravel-rpc","last_synced_at":"2026-05-20T01:05:31.029Z","repository":{"id":57034274,"uuid":"228518988","full_name":"overlu/laravel-rpc","owner":"overlu","description":"laravel rpc driver module, simple and easy to use","archived":false,"fork":false,"pushed_at":"2023-12-12T09:44:04.000Z","size":52,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-17T06:42:58.252Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/overlu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-12-17T02:47:22.000Z","updated_at":"2023-12-12T09:43:46.000Z","dependencies_parsed_at":"2022-08-23T23:51:11.703Z","dependency_job_id":null,"html_url":"https://github.com/overlu/laravel-rpc","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/overlu/laravel-rpc","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/overlu%2Flaravel-rpc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/overlu%2Flaravel-rpc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/overlu%2Flaravel-rpc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/overlu%2Flaravel-rpc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/overlu","download_url":"https://codeload.github.com/overlu/laravel-rpc/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/overlu%2Flaravel-rpc/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28111188,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-12-29T02:00:07.021Z","response_time":58,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-12-29T05:38:17.256Z","updated_at":"2025-12-29T05:38:19.793Z","avatar_url":"https://github.com/overlu.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"### 前言\n#### 项目介绍\noverlu/laravel-rpc是一款基于laravel的分布式开发部署扩展，`运行日志记录放在storage/logs/rpc`，包含4种方案：\n* 本地调用\n* MessageQueue调用 `异步`\n* RPC `同步`、`异步`\n* API `同步`\n\n#### 安装\n##### 1. 安装beanstalkd\n```shell script\n# 访问 http://kr.github.io/beanstalkd/download.html 下载beanstalkd-1.11.tar.gz\n\u003e tar -xf beanstalkd-1.11.tar.gz\n\u003e cd beanstalkd-1.11\n\u003e make\n# 查看beanstalkd参数信息\n\u003e ./beanstalkd -h\n# 启动beanstalkd，-b表示开启binlog，断电后重启自动恢复任务\n\u003e ./beanstalkd -l 127.0.0.1 -p 11300 -b /data/beanstalkd/binlog \u0026\n```\n\n##### 2. 安装扩展\n```shell script\nphp composer.phar require overlu/laravel-rpc\n# publish config\nphp artisan vendor:publish --provider=\"Overlu\\Rpc\\RpcServiceProvider\"\n```\n```php\n# 安装好Rpc扩展后，打开 config/app.php，注册如下服务提供者到 $providers 数组：\nOverlu\\Rpc\\RpcServiceProvider::class\n# 然后添加如下门面到 $aliaes 数组：\n'Rpc' =\u003e \\Overlu\\Rpc\\Facades\\Rpc::class\n```\n使用Nacos服务发现：\n```shell script\nphp composer.phar require overlu/laravel-reget\n```\n\u003e 具体使用查看：  \n[https://github.com/overlu/laravel-reget](https://github.com/overlu/laravel-reget)\n\n#### 配置\n```php\n/**\n * rpc.php\n * 基本信息配置\n */ \nreturn [\n    /**\n     * dev(default), production\n     * dev模式免签名验证\n     */\n    'environment' =\u003e 'dev',\n    /**\n     * 验证方式: white_ip_lists(default) / signature\n     */\n//    'verify_method' =\u003e 'white_ip_lists',\n    'verify_method' =\u003e 'signature',\n\n    'white_ip_lists' =\u003e [\n        '127.0.0.1',\n    ],\n    /**\n     * 秘钥，签名加密用，务必保证每个节点都一样\n     */\n    'key' =\u003e 'Q6Hc4pLmSMeYHVnqnRu68UcbC36RvIW2P7v3eQyAyxQ',\n\n    /**\n     * 签名有效时间，单位秒\n     */\n    'signature_expiry' =\u003e '600',\n\n    /**\n     * 异常处理驱动, rpc/default\n     */\n    'exception_driver' =\u003e 'rpc',\n\n    /**\n     * 是否打开调用日志\n     */\n    'log_info' =\u003e true,\n    'rpc_log_info_channel' =\u003e [\n        'driver' =\u003e 'daily',\n        'path' =\u003e storage_path('logs/rpc/info.log'),\n        'level' =\u003e 'info',\n//        'days' =\u003e 14,\n    ],\n    /**\n     * 是否打开错误日志\n     */\n    'log_error' =\u003e true,\n    'rpc_log_error_channel' =\u003e [\n        'driver' =\u003e 'daily',\n        'path' =\u003e storage_path('logs/rpc/error.log'),\n        'level' =\u003e 'error',\n//        'days' =\u003e 14,\n    ],\n\n    /**\n     * 配置beanstalkd\n     */\n    'beanstalkd' =\u003e [\n        'host' =\u003e env('BEANSTALKD_HOST', '127.0.0.1'),\n        'port' =\u003e env('BEANSTALKD_POST', '11300'),\n        'channel' =\u003e env('BEANSTALKD_CHANNEL', 'Lrpc_uDi7q'),\n    ],\n\n    /**\n     * rpc服务端口\n     */\n    'port' =\u003e env('RPC_SERVER_PORT', 1314),\n\n    /**\n     * 是否使用nacos服务\n     */\n    'use_nacos' =\u003e false,\n];\n\n```\n```php\n/**\n * module.php\n * 模块信息配置\n */\nreturn [\n    /**\n     * Module Mapping\n     * ModuleName =\u003e Namespace\\\\ModuleName\n     */\n    'mapping' =\u003e [\n//        'ModuleName' =\u003e 'Namespace\\\\ModuleName',\n    ],\n\n    /**\n     * 默认local驱动\n     */\n    'default_driver' =\u003e 'local',\n\n    /**\n     * module registration center\n     */\n    'registration' =\u003e [\n        'local' =\u003e [  // message queue监听使用，判断是否是自身服务\n//            'ModuleName'\n        ],\n        'mq' =\u003e [\n//            'ModuleName'\n        ],\n        'rpc' =\u003e [\n//            'ModuleName'\n        ],\n        'api' =\u003e [\n//            'ModuleName'\n        ],\n    ],\n\n    /**\n     * rpc服务地址模块映射\n     * 一个模块对应多个服务地址，使用','隔开\n     */\n    'hosts' =\u003e [\n//        'ModuleName' =\u003e '127.0.0.1',\n//        'ModuleName2' =\u003e '127.0.0.1,127.0.0.2',\n    ]\n];\n\n```\n\u003e 注意：如果同一个模块注册在多个API/RPC驱动服务器上，则系统会自动随机获取一个服务器连接\n\n#### 流程图  \n![QwSCM8.png](https://s2.ax1x.com/2019/12/09/QwSCM8.png)  \n\n#### Usage\n##### 修改配置文件module.php `本地配置文件模式`\n```php\n// 配置模块映射(demo)\n'mapping' =\u003e [\n    'Log' =\u003e '\\\\App\\\\RpcTest\\\\Log',\n    'SMS' =\u003e '\\\\App\\\\RpcTest\\\\SMS',\n    'News' =\u003e '\\\\App\\\\RpcTest\\\\News',\n]\n// 注册模块(demo)\n'registration' =\u003e [\n    'local' =\u003e ['Log'],\n    'mq' =\u003e ['SMS'],\n    'rpc' =\u003e [],\n    'api' =\u003e ['News'],\n]\n// 配置服务地址(demo)\n'hosts' =\u003e [\n    'Log' =\u003e '127.0.0.1',\n    'SMS' =\u003e '127.0.0.1,127.0.0.2',\n    'News' =\u003e '127.0.0.3'\n]\n```\n\n##### 修改配置 `nacos模式`\n__注册服务(demo)__  \n![YNPsGF.png](https://s1.ax1x.com/2020/05/12/YNPsGF.png) \n__配置模块参数(demo)__ \n![YN9Iw6.png](https://s1.ax1x.com/2020/05/12/YN9Iw6.png)  \n\n##### 初始化配置 `nacos模式`\n```shell script\n# demo\nphp artisan reget:listen demo.module.config --handle=\"Namespace\\ClassName\"\n```\n```php\n\u003c?php\n\nnamespace Namespace;\n\nClass ClassName\n{\n    /**\n     * @param $key\n     * @param $data\n     * @param $originData\n     */\n    public static function handle($key, $data, $originData)\n    {\n        Cache::set('module.registration', $data['registration']);\n        Cache::set('module.mapping', $data['mapping']);\n    }\n\n    /**\n     * @param \\Exception $exception\n     */\n    public static function error(\\Exception $exception)\n    {\n        dd($exception-\u003egetCode());\n    }\n}\n```\n##### 调用模块   \n___同步调用, 和原生new class一样的传参方式。___\n```php\n$result = Rpc::Module_Name('class_args1','class_args2')-\u003emethod('method_arg',['method_arg2_1','method_arg2_2']);\nvar_dump($result);\n```\n```php\n// 1. 获取远程实例化对象，注意：实例化模块需要事先在配置文件module.php中进行相关注册操作\n$news = Rpc::News();\n$log = Rpc::Log('debug', 'file');\n$sms = Rpc::SMS('ali');\n$sms = Rpc::SMS('huaxin');\n...\n```\n```php\n// 2. 调用远程对象方法，注意：和本地化调用以及传参一样，静态方法需要用::调用，普通方法用-\u003e调用\n$news_list = $new-\u003eget();\n$news_list_100 = $new-\u003eget(100);\ndump($news_list, $news_list_100);\n$log::debug('log debug info');\n$sms-\u003esend(18888888888, '我是同步发送短信方式');\n...\n```\n___异步调用，实例化和传参见同步调用___\n```php\n// 异步调用，需要在实例化模块前面加上\"_\"\n$sms = Rpc::_SMS();\n$sms-\u003esend(18888888888, '我是异步发送短信方式');\n\n// 异步生成新闻\nRpc::_News()-\u003ecreate('news content');\n// 新增回调函数，调用的函数名前面加上\"_\"，在该回调函数内处理回调数据\npublic function _create($result)\n{\n    // 在这里处理异步回调数据\n    if($result) {\n        echo 'create success';\n    } else {\n        echo 'create faild';\n    }\n}\n```\n\u003e 注意：异步调用无返回值，需要新增一接收回调函数，普通函数名前面加上下划线`_`。异步调用目前只支持mq/rpc驱动\n\n#### 服务\n*  启动服务\n```shell script\nphp artisan rpc:start mq \nphp artisan rpc:start rpc \nphp artisan rpc:start all \n# 常驻后台\nphp artisan rpc:start mq --d\nphp artisan rpc:start rpc --d\nphp artisan rpc:start all --d\n```\n*  关闭服务\n```shell script\nphp artisan rpc:stop mq \nphp artisan rpc:stop rpc \nphp artisan rpc:stop all \n```\n*  重启服务\n```shell script\nphp artisan rpc:reload mq \nphp artisan rpc:reload rpc \nphp artisan rpc:reload all\n# 常驻后台\nphp artisan rpc:reload mq --d\nphp artisan rpc:reload rpc --d\nphp artisan rpc:reload all --d\n```\n*  服务状态\n```shell script\nphp artisan rpc:status mq \nphp artisan rpc:status rpc \n```\n\u003e 建议配合supervisor管理进程\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foverlu%2Flaravel-rpc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foverlu%2Flaravel-rpc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foverlu%2Flaravel-rpc/lists"}