{"id":17955664,"url":"https://github.com/limingxinleo/phalcon-thrift-project","last_synced_at":"2025-10-18T15:02:48.991Z","repository":{"id":57015124,"uuid":"98297448","full_name":"limingxinleo/phalcon-thrift-project","owner":"limingxinleo","description":"基于Thrift的Go和PHP RPC服务","archived":false,"fork":false,"pushed_at":"2018-03-04T11:57:09.000Z","size":3281,"stargazers_count":23,"open_issues_count":0,"forks_count":4,"subscribers_count":4,"default_branch":"thrift","last_synced_at":"2025-06-04T09:05:21.689Z","etag":null,"topics":["go","phalcon","php","project","swoole","thrift"],"latest_commit_sha":null,"homepage":"","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/limingxinleo.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}},"created_at":"2017-07-25T11:08:13.000Z","updated_at":"2022-04-21T02:07:17.000Z","dependencies_parsed_at":"2022-08-22T09:30:33.954Z","dependency_job_id":null,"html_url":"https://github.com/limingxinleo/phalcon-thrift-project","commit_stats":null,"previous_names":["limingxinleo/thrift-go-phalcon-project"],"tags_count":14,"template":false,"template_full_name":null,"purl":"pkg:github/limingxinleo/phalcon-thrift-project","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/limingxinleo%2Fphalcon-thrift-project","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/limingxinleo%2Fphalcon-thrift-project/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/limingxinleo%2Fphalcon-thrift-project/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/limingxinleo%2Fphalcon-thrift-project/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/limingxinleo","download_url":"https://codeload.github.com/limingxinleo/phalcon-thrift-project/tar.gz/refs/heads/thrift","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/limingxinleo%2Fphalcon-thrift-project/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264837928,"owners_count":23671119,"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":["go","phalcon","php","project","swoole","thrift"],"created_at":"2024-10-29T10:31:38.508Z","updated_at":"2025-10-18T15:02:48.896Z","avatar_url":"https://github.com/limingxinleo.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PHALCON框架结构\n\n[![Total Downloads](https://poser.pugx.org/limingxinleo/phalcon-project/downloads)](https://packagist.org/packages/limingxinleo/phalcon-project)\n[![Latest Stable Version](https://poser.pugx.org/limingxinleo/phalcon-project/v/stable)](https://packagist.org/packages/limingxinleo/phalcon-project)\n[![Latest Unstable Version](https://poser.pugx.org/limingxinleo/phalcon-project/v/unstable)](https://packagist.org/packages/limingxinleo/phalcon-project)\n[![License](https://poser.pugx.org/limingxinleo/phalcon-project/license)](https://packagist.org/packages/limingxinleo/phalcon-project)\n\n\n[Phalcon 官网](https://docs.phalconphp.com/zh/latest/index.html)\n\n[wiki](https://github.com/limingxinleo/simple-subcontrollers.phalcon/wiki)\n\n## 安装\n1. 安装项目\n~~~\ncomposer create-project limingxinleo/thrift-go-phalcon-project\n~~~\n2. 使用Composer安装Thrift扩展后，把go的扩展包拷贝到GOPATH中(或建立软连接)。\n~~~\nln -s  /your/path/to/thrift-go-phalcon-project/vendor/apache/thrift/lib/go/thrift thrift\n~~~\n3. 编译服务 \n- Go 使用 thrift -r --gen go:thrift_import=thrift App.thrift\n- Php 使用 thrift -r --gen php:server,psr4 App.thrift\n\n4. Go服务安装\n~~~\n从GO官网下载编译好的压缩包 例如 go1.8.3.linux-amd64.tar.gz\n$ tar -xzf go1.8.3.linux-amd64.tar.gz\n$ mv go /usr/local/go/1.8.3\n$ vim /etc/profile \nexport GOROOT='/usr/local/go/1.8.3' # 没有文件夹则新建\nexport GOPATH='/usr/local/go/libs/' # 没有文件夹则新建\nexport PATH=$GOROOT/bin:$PATH\n$ go get -u github.com/kardianos/govendor\n$ cd /usr/local/go/libs/src/github.com/kardianos/govendor/\n$ go build\n$ cd /usr/local/bin\n$ ln -s /usr/local/go/libs/src/github.com/kardianos/govendor/govendor govendor\n~~~\n\n## Go\u0026Swoole RPC 服务\n* Go\nthrift/gen-go/main.go\n~~~\n# RPC服务注册方法\nserver.RegisterProcessor(\"app\", service.NewAppProcessor(\u0026impl.App{}));\n~~~\n\n* Swoole\napp/tasks/Thrift/Service.php\n~~~\n$handler = new AppHandler();\n$processor-\u003eregisterProcessor('app', new AppProcessor($handler));\n~~~\n\n## 服务实现\n* Swoole\napp/thrift/Services/AppHandle.php\n~~~php\n\u003c?php \nnamespace App\\Thrift\\Services;\n\nuse MicroService\\AppIf;\n\nclass AppHandler extends Handler implements AppIf\n{\n    public function version()\n    {\n        return $this-\u003econfig-\u003eversion;\n    }\n\n}\n~~~\n\n## 负载均衡\n- Nginx Stream负载均衡已经十分强大了，自带健康检查。[TCP负载均衡](https://github.com/limingxinleo/note/blob/master/nginx/nginx.md#tcp负载均衡)\n\n## 服务发现\n1. 项目本人已内置基于Thrift的注册中心功能\n- 已实现Swoole服务注册中心\n- 已实现Go服务注册中心\n\n2. 或者配合[注册中心](https://github.com/limingxinleo/service-registry-swoole-phalcon.git)一起使用\napp/tasks/Thrift/ServiceTask.php\n~~~\nprotected function beforeServerStart(swoole_server $server)\n{\n    parent::beforeServerStart($server); // TODO: Change the autogenerated stub\n\n    // 增加服务注册心跳进程\n    $worker = new swoole_process(function (swoole_process $worker) {\n        $client = new swoole_client(SWOOLE_SOCK_TCP);\n        if (!$client-\u003econnect(env('REGISTRY_IP'), env('REGISTRY_PORT'), -1)) {\n            exit(\"connect failed. Error: {$client-\u003eerrCode}\\n\");\n        }\n        swoole_timer_tick(5000, function () use ($client) {\n            $service = env('REGISTRY_SERVICE', 'github');\n            $data = [\n                'service' =\u003e $service,\n                'ip' =\u003e env('SERVICE_IP'),\n                'port' =\u003e env('SERVICE_PORT'),\n                'nonce' =\u003e time(),\n                'register' =\u003e true,\n                'sign' =\u003e 'xxx',\n            ];\n\n            $client-\u003esend(json_encode($data));\n            $result = $client-\u003erecv();\n\n            $result = json_decode($result, true);\n            if ($result['success']) {\n                foreach ($result['services'] as $key =\u003e $item) {\n                    Redis::hset($service, $key, json_encode($item));\n                }\n            }\n        });\n    });\n\n    $server-\u003eaddProcess($worker);\n}\n\n~~~\n\n\n## Thrift 数据类型\n1. 基本类型（括号内为对应的Java类型）：\n~~~\nbool（boolean）: 布尔类型(TRUE or FALSE)\nbyte（byte）: 8位带符号整数\ni16（short）: 16位带符号整数\ni32（int）: 32位带符号整数\ni64（long）: 64位带符号整数\ndouble（double）: 64位浮点数\nstring（String）: 采用UTF-8编码的字符串\n~~~\n\n2. 特殊类型（括号内为对应的Java类型）\n~~~\nbinary（ByteBuffer）：未经过编码的字节流\n~~~\n\n3. Structs（结构）：\n~~~\nstruct UserProfile {\n    1: i32 uid,\n    2: string name,\n    3: string blurb\n}\n\nstruct UserProfile {\n    1: i32 uid = 1,\n    2: string name = \"User1\",\n    3: string blurb\n}\n~~~\n\n4. 容器，除了上面提到的基本数据类型，Thrift还支持以下容器类型：\n\n\u003e list(java.util.ArrayList)\n\u003e set(java.util.HashSet)\n\u003e map（java.util.HashMap）\n\n~~~\nstruct Node {\n    1: i32 id,\n    2: string name,\n    3: list\u003ci32\u003e subNodeList,\n    4: map\u003ci32,string\u003e subNodeMap,\n    5: set\u003ci32\u003e subNodeSet\n}\n\nstruct SubNode {\n    1: i32 uid,\n    2: string name,\n    3: i32 pid\n}\n\nstruct Node {\n    1: i32 uid,\n    2: string name,\n    3: list\u003csubNode\u003e subNodes\n}\n~~~\n\n5. 服务\n~~~\nservice UserStorage {\n    void store(1: UserProfile user),\n    UserProfile retrieve(1: i32 uid)\n}\n~~~\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flimingxinleo%2Fphalcon-thrift-project","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flimingxinleo%2Fphalcon-thrift-project","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flimingxinleo%2Fphalcon-thrift-project/lists"}