{"id":18702485,"url":"https://github.com/pretty66/fastcar","last_synced_at":"2025-06-28T17:06:28.654Z","repository":{"id":192826558,"uuid":"687397783","full_name":"pretty66/fastcar","owner":"pretty66","description":"PHP long connection proxy, eliminates short links and reduces request latency","archived":false,"fork":false,"pushed_at":"2023-10-04T07:53:29.000Z","size":776,"stargazers_count":15,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-26T03:51:16.911Z","etag":null,"topics":["keep-alive","long-connection","php","proxy"],"latest_commit_sha":null,"homepage":"","language":"Go","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/pretty66.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,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-09-05T09:21:33.000Z","updated_at":"2024-07-01T09:01:24.000Z","dependencies_parsed_at":null,"dependency_job_id":"e3509dba-32d4-49c1-a0d5-6c0aeaf900f1","html_url":"https://github.com/pretty66/fastcar","commit_stats":null,"previous_names":["pretty66/fastcar"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pretty66%2Ffastcar","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pretty66%2Ffastcar/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pretty66%2Ffastcar/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pretty66%2Ffastcar/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pretty66","download_url":"https://codeload.github.com/pretty66/fastcar/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248543882,"owners_count":21121838,"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":["keep-alive","long-connection","php","proxy"],"created_at":"2024-11-07T11:45:56.661Z","updated_at":"2025-04-12T08:51:21.786Z","avatar_url":"https://github.com/pretty66.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"![logo](./docs/fastcar-logo.png)\n\n[中文](./README.md) \u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp; [English](./README_EN.md)\n---\n\n# Fastcar - PHP 长连接代理\n\nFastcar 是使用 Go 语言编写的代理程序，旨在为 PHP 程序在网络请求时提供长连接支持。通过 Unix 域套接字通信，Fastcar 可以为 PHP 程序赋能，让它们能够保持长连接，从而提升网络请求性能。\n```text\n+---------------------+              +----------------------+               +---------------------+\n|                     |              |                      |               |                     |\n|    PHP Program      |   \u003c-------\u003e  |       FastCar        |    \u003c------\u003e   |   Remote Server     |\n|                     |    unix      |                      |    HTTP/HTTPS |                     |\n|    Network Request  |    domain    |   +--------------+   |    Request    |   Network Request   |\n|                     |    socket    |   |              |   |               |                     |\n+---------------------+              |   | Connection   |   |               +---------------------+\n                                     |   |   Pool       |   |\n                                     |   +--------------+   |\n                                     +----------------------+\n```\n## 简介与技术原理\n\nFastcar 部署在 PHP 程序所在的服务器上，通过 Unix 域套接字与 PHP 程序进行通信，实现高效的连接。其核心能力包括：\n\n- **通信方式**：使用 Unix 域套接字（unix domain socket）进行高效通信，降低了网络开销。\n\n- **判断请求协议**：Fastcar 从 Unix 域套接字接收 PHP 程序的网络请求，根据请求协议判断是 HTTP 请求还是 HTTPS 请求;\n对于 HTTP 请求，Fastcar 直接转发给远程服务器; 对于 HTTPS 请求，Fastcar 会暂时伪装成服务端，与 PHP 程序在内存通信中完成 TLS 握手，然后再与远程服务器建立 TLS 连接，实现请求转发。\n\n- **连接池**：Fastcar 维护连接池，将与远程服务器的连接回收，实现连接的复用，降低资源消耗。\n\n## PHP 网络请求的挑战\n在传统的网络请求中，PHP 程序使用短连接模式，这可能导致以下问题：\n- 性能问题：频繁的连接建立和关闭导致性能下降，影响 PHP 程序的整体响应速度。\n- 延迟增加：短连接模式会增加请求的延迟，尤其在高并发场景下，连接开销变得显著。\n- 资源浪费：频繁的连接开销和关闭会浪费服务器和网络资源，影响资源的有效利用。\n\n## Fastcar 的优势\n\nFastcar 提供了多重优势，使其成为 PHP 长连接代理的理想选择：\n\n- **HTTPS 伪装握手**：针对https服务的访问Fastcar会伪装服务端进行 TLS 握手，代替php程序同目标服务建立tls连接，并保持连接复用，能显著降低php短连接频繁握手导致的请求延迟。\n\n- **长连接支持**：通过维护连接池，Fastcar 提供长连接支持，可以接管节点上所有的php程序网络请求，达到多服务连接共用；例如k8s形式单台节点上部署多个pod形式的业务能大大降低连接建立的开销。\n\n- **资源优化**：Fastcar本身非常轻量，只占用很少的系统资源，同时通过连接池的复用，降低了服务器和网络资源的消耗。\n\n## 性能对比\n分别请求百度翻译api的http和https地址，对比使用fastcar和php直接请求的延迟对比，如下图所示：\n\n### http请求延迟对比\n直接请求和通过fastcar请求各100次，使用fastcar后平均延迟降低了约 **34.8%**\n![http延迟](./docs/http_delay.png)\n\n### https请求延迟对比\n直接请求和通过fastcar请求各100次，使用fastcar后平均延迟降低了约 **48.4%**\n![https延迟](./docs/https_delay.png)\n\n\n### 使用fastcar可以显著降低php程序的网络请求延迟，使请求的延迟趋于更加稳定的状态；在https请求模式下，fastcar的优势更加明显。\n\n----\n\n## 快速开始\n### 部署fastcar\n```shell\n$ git clone https://github.com/pretty66/fastcar.git\n$ cd fastcar\n$ make build\n$\n$ ./fastcar -h\nUsage of ./fastcar:\n  -cert string\n        tls cert file, empty auto create\n  -key string\n        tls key file, empty auto create\n  -proxy string\n        proxy url: scheme://user:password@host:port\n  -unix string\n        unix socket addr (default \"/tmp/fastcar.sock\")\n```\n```shell\n# run\nnohup ./fastcar -unix /tmp/fastcar.sock \u003e debug.log 2\u003e\u00261 \u0026\n```\n\n### php程序配置\n```php\n// Disable certificate validation\ncurl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);\ncurl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);\n// Set Unix socket file path\ncurl_setopt($ch, CURLOPT_UNIX_SOCKET_PATH, '/tmp/fastcar.sock');\n```\n参考示例：[访问百度翻译api](./example/curl.php)\n\n## 贡献\n\n欢迎对 Fastcar 提出问题、报告 Bug 或者提供改进建议。你可以通过 GitHub Issues 来与我交流。\n\n## License\nFastcar is under the Apache 2.0 license. See the [LICENSE](./LICENSE) directory for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpretty66%2Ffastcar","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpretty66%2Ffastcar","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpretty66%2Ffastcar/lists"}