{"id":20441719,"url":"https://github.com/mix-php/grpc-skeleton","last_synced_at":"2026-04-15T21:32:41.864Z","repository":{"id":57017775,"uuid":"386156545","full_name":"mix-php/grpc-skeleton","owner":"mix-php","description":"gRPC development skeleton","archived":false,"fork":false,"pushed_at":"2023-04-19T02:02:39.000Z","size":40,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-09-14T14:57:10.463Z","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":null,"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":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-07-15T03:59:31.000Z","updated_at":"2022-05-01T12:32:54.000Z","dependencies_parsed_at":"2024-11-15T09:36:33.741Z","dependency_job_id":"20111336-26d6-4c16-930e-6e1612babc3d","html_url":"https://github.com/mix-php/grpc-skeleton","commit_stats":{"total_commits":28,"total_committers":3,"mean_commits":9.333333333333334,"dds":0.1428571428571429,"last_synced_commit":"273849334f298baca469757f3830760b62e60ce4"},"previous_names":[],"tags_count":25,"template":true,"template_full_name":null,"purl":"pkg:github/mix-php/grpc-skeleton","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mix-php%2Fgrpc-skeleton","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mix-php%2Fgrpc-skeleton/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mix-php%2Fgrpc-skeleton/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mix-php%2Fgrpc-skeleton/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mix-php","download_url":"https://codeload.github.com/mix-php/grpc-skeleton/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mix-php%2Fgrpc-skeleton/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31861401,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-15T15:24:51.572Z","status":"ssl_error","status_checked_at":"2026-04-15T15:24:39.138Z","response_time":63,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":"2024-11-15T09:34:24.358Z","updated_at":"2026-04-15T21:32:41.847Z","avatar_url":"https://github.com/mix-php.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# gRPC development skeleton\n\n帮助你快速搭建 gRPC 项目骨架，并指导你如何使用该骨架的细节，骨架默认开启了 SQL、Redis 日志，压测前请先关闭 `.env` 的 `APP_DEBUG`\n\n## 安装\n\n\u003e 需要先安装 [Swoole](https://wiki.swoole.com/#/environment)\n\n- Swoole \u003e= 4.4.4: https://wiki.swoole.com/#/environment\n- 需要开启 `--enable-http2`\n\n```\ncomposer create-project --prefer-dist mix/grpc-skeleton grpc\n```\n\n## 快速开始\n\n启动 Swoole 多进程服务\n\n```\ncomposer run-script --timeout=0 swoole:start\n```\n\n启动 Swoole 协程服务\n\n```\ncomposer run-script --timeout=0 swooleco:start\n```\n\n## 执行脚本\n\n- `composer run-script` 命令中的 `--timeout=0` 参数是防止 composer [执行超时](https://getcomposer.org/doc/06-config.md#process-timeout)\n- `composer.json` 定义了命令执行脚本，对应上面的执行命令\n\n```json\n\"scripts\": {\n    \"swoole:start\": \"php bin/swoole.php\",\n    \"swooleco:start\": \"php bin/swooleco.php\",\n    \"cli:clearcache\": \"php bin/cli.php clearcache\"\n}\n```\n\n当然也可以直接下面这样启动，效果是一样的，但是 `scripts` 能帮你记录到底有哪些可用的命令，同时在IDE中调试更加方便。\n\n```\nphp bin/swoole.php start\n```\n\n## 编写一个 gRPC 接口\n\n首先修改根目录 `.env` 文件的数据库信息\n\n然后在 `proto` 目录创建 `greeter.proto` 文件，并根据 [使用说明](https://github.com/mix-php/grpc#%E9%80%9A%E8%BF%87-proto-%E7%94%9F%E6%88%90-php-%E4%BB%A3%E7%A0%81) 将 .proto 文件生成为 PHP 代码\n\n```\nprotoc --php_out=. --mix_out=. greeter.proto\n```\n\n然后创建一个新的服务 `src/Service/Say.php`\n\n- `Say` 类实现了代码生成器生成的 `Php\\Micro\\Grpc\\Greeter\\SayInterface` 接口\n\n```php\n\u003c?php\n\nnamespace App\\Service;\n\nuse Mix\\Grpc\\Context;\nuse Php\\Micro\\Grpc\\Greeter\\Request;\nuse Php\\Micro\\Grpc\\Greeter\\Response;\n\n/**\n * Class Say\n * @package App\\Service\n */\nclass Say implements \\Php\\Micro\\Grpc\\Greeter\\SayInterface\n{\n\n    /**\n     * @param Context $context\n     * @param Request $request\n     * @return Response\n     */\n    public function Hello(Context $context, Request $request): Response\n    {\n        $response = new Response();\n        $response-\u003esetMsg(sprintf('hello, %s', $request-\u003egetName()));\n        return $response;\n    }\n\n}\n```\n\n在 `src/Grpc.php` 中将服务注册到服务器\n\n```php\n$server-\u003eregister(Say::class);\n```\n\n重新启动服务器后方可测试新开发的接口\n\n\u003e 实际开发中使用 PhpStorm 的 Run 功能，只需要点击一下重启按钮即可\n\n```\n// 查找进程 PID\nps -ef | grep swoole\n\n// 通过 PID 停止进程\nkill PID\n\n// 重新启动进程\ncomposer run-script swoole:start\n```\n\n## 如何使用 gRPC 客户端\n\n- [mix/grpc#客户端调用一个 gRPC 服务](https://github.com/mix-php/grpc#%E5%AE%A2%E6%88%B7%E7%AB%AF%E8%B0%83%E7%94%A8%E4%B8%80%E4%B8%AA-grpc-%E6%9C%8D%E5%8A%A1)\n\n## 使用容器中的对象\n\n容器采用了一个简单的单例模式，你可以修改为更加适合自己的方式。\n\n- 数据库：[mix/database](https://github.com/mix-php/database#readme)\n\n```\nDB::instance()\n```\n\n- Redis：[mix/redis](https://github.com/mix-php/redis#readme)\n\n```\nRDS::instance()\n```\n\n- 日志：[monolog/monolog](https://seldaek.github.io/monolog/doc/01-usage.html)\n\n```\nLogger::instance()\n```\n\n- 配置：[hassankhan/config](https://github.com/hassankhan/config#getting-values)\n\n```\nConfig::instance()\n```\n\n## 部署\n\n线上部署启动时，修改 `shell/server.sh` 脚本中的绝对路径和参数\n\n```\nphp=/usr/local/bin/php\nfile=/project/bin/swoole.php\ncmd=start\nnumprocs=1\n```\n\n启动管理\n\n```\nsh shell/server.sh start\nsh shell/server.sh stop\nsh shell/server.sh restart\n```\n\ngRPC 通常都是内部使用，使用内网 `SLB` 代理到服务器IP或者直接使用 IP:PORT 调用\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%2Fgrpc-skeleton","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmix-php%2Fgrpc-skeleton","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmix-php%2Fgrpc-skeleton/lists"}