单线读取PHP,例如Dart或nodejs

发布于 2025-02-08 12:28:46 字数 823 浏览 1 评论 0原文

我有一个服务a功能相当有限的功能:当客户端请求时,它只是将请求发送到服务b。这可能需要花费很多时间:Service A等待Service B大多数时间(〜99%)的响应。如果我从头开始编写它,我会使用一些单线程环境(例如Dart或Node),但问题在于它是用PHP编写的。因此,每个HTTP请求都会产生一个子过程,并且每个请求都使用一个CPU。因此,没有充分的理由使用大量的CPU:他们每个人只需等待Service b的响应。

这是我所拥有的图像:

相反,我宁愿有一个带有一个线程的过程,例如在nodejs中:

那么,我的问题是,当仅使用单个CPU时,我该如何实现这种nodejs的行为?

我已经检查了一些异步库,例如swoole,reactphp,amphp等,但是它们大多提到多路复用,例如当我有几个并发请求时,我可以同时发送,而不是顺序发送它们。但这不是我需要的。

那么,我有什么选择?

I have a service A with pretty limited functionality: when clients request it, it just sends a request to service B. It can take quite some time: service A waits for a response from service B most (~99%) of the time. If I'd written it from scratch, I would have used some single-threaded environment like dart or node, but the problem is that it's written in php. So a child process is spawned per each http request, and each of them utilizes one CPU. So huge amount of CPUs is utilized for no good reason: each of them just waits for a response from service B.

Here is an image elaborating on what I have:
enter image description here

Instead, I'd rather have a single process with a single thread, like in NodeJS:
enter image description here

So, my question is how can I achieve this nodeJS-like behavior, when only single CPU is used?

I've checked some async libraries like swoole, reactphp, amphp, etc, but they mostly mention multiplexing, like when I have several concurrent requests and I can send them concurrently, not sequentially. But it's not what I need.

So, what options do I have?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文