{"id":20441760,"url":"https://github.com/mix-php/micro","last_synced_at":"2025-04-12T23:32:49.427Z","repository":{"id":57017782,"uuid":"265527761","full_name":"mix-php/micro","owner":"mix-php","description":"PHP microservice development framework deeply integrated with go-micro ecology","archived":false,"fork":false,"pushed_at":"2020-09-30T06:44:42.000Z","size":25,"stargazers_count":21,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-01-22T19:20:39.585Z","etag":null,"topics":["etcd","hystrix","micro","microservice","mix","php-micro","swoole","zipkin"],"latest_commit_sha":null,"homepage":"https://openmix.org/mix-php","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mix-php.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":"2020-05-20T10:17:17.000Z","updated_at":"2023-08-29T13:37:44.000Z","dependencies_parsed_at":"2022-08-22T11:31:41.433Z","dependency_job_id":null,"html_url":"https://github.com/mix-php/micro","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mix-php%2Fmicro","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mix-php%2Fmicro/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mix-php%2Fmicro/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mix-php%2Fmicro/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mix-php","download_url":"https://codeload.github.com/mix-php/micro/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248647257,"owners_count":21139081,"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":["etcd","hystrix","micro","microservice","mix","php-micro","swoole","zipkin"],"created_at":"2024-11-15T09:34:35.940Z","updated_at":"2025-04-12T23:32:49.402Z","avatar_url":"https://github.com/mix-php.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Mix Micro\n\n与 go-micro 生态深度集成的 php 微服务开发框架\n\nPHP microservice development framework deeply integrated with go-micro ecology\n\n## 安装\n\n要求：\n\n- Swoole \u003e= 4.5.0: https://wiki.swoole.com/#/environment\n\n```\ncomposer require mix/micro\n```\n\n## 概述\n\n在很多 Swoole 框架自建微服务生态的时候，我认为微服务生态要是能与主流生态直接无缝通信可能更具有实用价值，Mix 从 V2.1 开始完全切换为单线程协程，这一特性非常适合微服务的打造，同时 Mix 一直都是 Go 风格框架，因此我决定将微服务融入 go-micro 生态，让 Mix 框架用户能与 go-micro 编写的微服务直接代码级无缝通信，并且能直接使用 go-micro 运行时工具包的网关、代理、Dashboard 等全部微服务治理基础设施，让 PHP 与 Go 能一起开发高性能微服务，取长补短。\n\n- Mix Micro：动态语言，开发效率高，view 模板渲染更加适合，单线程协程没有锁的烦恼，try/catch 不用忍受 go 大量 err 处理的烦恼，更加完善的 OOP 让业务封装更加人性。\n- Go Micro: 静态语言，编译时即可过滤大量代码问题，CPU 密集型计算更加擅长，原生的协程库生态更加丰富。\n\n基于以上 Mix 打造了可独立使用的 [Mix Micro](https://github.com/mix-php/micro) 同时还提供了包含大量代码的 [Mix Micro Skeleton](https://github.com/mix-php/mix-micro-skeleton) 微服务开发骨架。\n\n支持的服务器\n\n- [Mix gRPC](https://github.com/mix-php/grpc) \n- [Mix JSON-RPC](https://github.com/mix-php/json-rpc)\n- [Mix Http Server](https://github.com/mix-php/http-server)\n\n支持的注册中心、配置中心\n\n- [Mix Micro Etcd](https://github.com/mix-php/micro-etcd)\n\n支持的网关\n\n- [Micro](https://github.com/micro/micro) v1, v2\n\n其他微服务治理组件\n\n- [Mix Micro Hystrix](https://github.com/mix-php/micro-hystrix) \n- [Mix Tracing Zipkin](https://github.com/mix-php/tracing-zipkin) \n\n## 使用\n\n### 创建一个 gRPC 服务器\n\n详细的 gRPC 服务编写请查看：\n\n- [Mix gRPC](https://github.com/mix-php/grpc)\n\n```php\n$server = new \\Mix\\Grpc\\Server('0.0.0.0'); // 默认会随机分配端口，也可以指定\n$server-\u003eregister(SayService::class);\n```\n\n### 创建一个注册中心\n\n```php\n$registry = new \\Mix\\Micro\\Etcd\\Registry('http://127.0.0.1:2379/v3');\n```\n\n### 创建一个配置中心\n\n```php\n$config = new \\Mix\\Micro\\Etcd\\Config('http://127.0.0.1:2379/v3');\n$config-\u003elisten($eventDispatcher); // PSR-14 Event Dispatcher\n```\n\n### 执行一个微服务\n\n启动后会自动监听 SIGINT, SIGTERM, SIGQUIT 信号，自动优雅停止，如果想自己处理信号，传入 `Micro::signal(false)` 配置\n\n```php\nuse Mix\\Micro\\Micro;\n\nMicro::newService(\n    Micro::server($server),\n    Micro::registry($registry),\n    Micro::config($config),\n    Micro::logger($logger), // PSR-3 Logger\n    Micro::version('latest'),\n    Micro::metadata(['foo' =\u003e 'bar'])\n)-\u003erun();\n```\n\n执行后日志打印：\n\n```php\n[2020-05-21 21:01:18] API.INFO: Server started [0.0.0.0:51438]\n[2020-05-21 21:01:18] API.INFO: Register service [php.micro.grpc.greeter-2938109e-9b63-11ea-80bd-000057bdb82e]\n```\n\n启动后的微服务可使用 [Micro](https://micro.mu/docs/runtime.html) 工具包 API Gateway、Web Dashboard、Web Proxy 等多种微服务管理工具，也可在 PHP 代码中使用 [Mix gRPC](https://github.com/mix-php/grpc) 的 Client 直接调用 [go-micro](https://github.com/micro/go-micro) 编写的微服务。\n\n## License\n\nApache License Version 2.0, http://www.apache.org/licenses/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmix-php%2Fmicro","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmix-php%2Fmicro","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmix-php%2Fmicro/lists"}