{"id":19832933,"url":"https://github.com/tinywan/webman-rpc","last_synced_at":"2025-05-01T16:33:46.357Z","repository":{"id":57070188,"uuid":"471751289","full_name":"Tinywan/webman-rpc","owner":"Tinywan","description":"simple rpc service for webman plugin","archived":false,"fork":false,"pushed_at":"2024-10-22T02:56:12.000Z","size":42,"stargazers_count":18,"open_issues_count":1,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-10-31T20:13:04.083Z","etag":null,"topics":["php","rpc","rpc-server","tinywan","webman","webman-framework","workerman"],"latest_commit_sha":null,"homepage":"https://www.workerman.net/plugin/38","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/Tinywan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2022-03-19T16:30:01.000Z","updated_at":"2024-10-22T02:56:15.000Z","dependencies_parsed_at":"2023-11-23T07:25:36.479Z","dependency_job_id":"09308a97-55ef-4f5d-ab62-5ee3c7bacc54","html_url":"https://github.com/Tinywan/webman-rpc","commit_stats":{"total_commits":27,"total_committers":1,"mean_commits":27.0,"dds":0.0,"last_synced_commit":"b04765e30911a73c7f53aaef8d23895b1685adb8"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tinywan%2Fwebman-rpc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tinywan%2Fwebman-rpc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tinywan%2Fwebman-rpc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tinywan%2Fwebman-rpc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Tinywan","download_url":"https://codeload.github.com/Tinywan/webman-rpc/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224269111,"owners_count":17283630,"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","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":["php","rpc","rpc-server","tinywan","webman","webman-framework","workerman"],"created_at":"2024-11-12T11:39:03.656Z","updated_at":"2024-11-12T11:39:04.184Z","avatar_url":"https://github.com/Tinywan.png","language":"PHP","readme":"# simple rpc service for webman plugin\n\n[![Latest Stable Version](http://poser.pugx.org/tinywan/rpc/v)](https://packagist.org/packages/tinywan/rpc) \n[![Total Downloads](http://poser.pugx.org/tinywan/rpc/downloads)](https://packagist.org/packages/tinywan/rpc) \n[![Latest Unstable Version](http://poser.pugx.org/tinywan/rpc/v/unstable)](https://packagist.org/packages/tinywan/rpc) \n[![License](http://poser.pugx.org/tinywan/rpc/license)](https://packagist.org/packages/tinywan/rpc)\n[![PHP Version Require](http://poser.pugx.org/tinywan/rpc/require/php)](https://packagist.org/packages/tinywan/rpc)\n\n## 安装\n\n```shell\ncomposer require tinywan/rpc\n```\n\n## 使用\n\n### 服务端服务\n\n新建 `service/User.php` 服务（目录不存在自行创建）\n```php\nnamespace service;\nclass User\n{\n    public function get($args)\n    {\n        return response_rpc_json(0,'获取成功', $args);\n    }\n}\n```\n### 客户端调用\n\n```php\n// 建立socket连接到内部推送端口\n$resource = stream_socket_client('tcp://127.0.0.1:9512', $errorCode, $errorMessage);\nif (false === $resource) {\n    throw new \\Exception('rpc failed to connect: '.$errorMessage);\n}\n$request = [\n    'class'   =\u003e 'user',\n    'method'  =\u003e 'get',\n    'args'    =\u003e [\n        [\n            'uid' =\u003e 2023,\n            'username' =\u003e 'Tinywan',\n        ]\n    ]\n];\n// 发送数据，注意5678端口是Text协议的端口，Text协议需要在数据末尾加上换行符\nfwrite($resource, json_encode($request).\"\\n\"); \n// 读取推送结果\n$result = fgets($resource, 10240000);\nfclose($resource);\n// 解析JSON字符串\n$result = json_decode($result, true);\nvar_export($result);\n```\n\n请求响应结果\n```json\n{\n    \"code\": 0,\n    \"msg\": \"用户列表\",\n    \"data\": {\n      \"uid\": 2024,\n      \"username\": \"Tinywan\"\n    }\n}\n```\n\n请求响应异常结果\n```json\n{\n    \"code\": 404,\n    \"msg\": \"接口调用类不存在\",\n    \"data\": {}\n}\n```\n\n## 在client端发起一个远程伪代码中\n\nclient端调用server端 如果server端的代码为本地则是本地调用，如果server端的代码在另外一台机器就需要远程调用（Rpc协议）\n\n1. 服务端通过插件tinywan/rpc自定义进程实现一个文本text协议服务\n2. 客户端将Server和B方法，以及B方法可能带有的参数序列化\n3. 通过stream_socket_client把序列化的消息发送给服务端\n4. 服务端接收消息并反序列化\n5. 通过反射调用调用服务端的Server类下的B方法\n6. 服务端Server类B方法返回的结果序列化\n7. 将返回的序列化结果通过stream_socket_client发送给客户端\n8. 客户端通过反序列化得到结果\n\n## 调用编码\n```phpregexp\n1. 接口方法  \n   包括接口名、方法名  \n2. 方法参数  \n   包括参数类型、参数值  \n3. 调用属性  \n   包括调用属性信息，例如调用附件隐式参数、调用超时时间等  \n-- 返回编码 --  \n1. 返回结果  \n   接口方法中定义的返回值  \n2. 返回码  \n   异常返回码  \n3. 返回异常信息  \n   调用异常信息  \n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftinywan%2Fwebman-rpc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftinywan%2Fwebman-rpc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftinywan%2Fwebman-rpc/lists"}