管理持久 PHP 脚本进程的推荐方法?

发布于 2024-08-27 21:12:36 字数 505 浏览 7 评论 0原文

首先 - 你好,这是我的第一个 Stack Overflow 问题,所以我会尽力正确沟通。

我的问题的标题可能有点含糊,所以让我立即对其进行扩展:

我正在计划一个项目,其中涉及从多个“流”API 获取数据输入,Twitter 就是一个例子。我有一个用 PHP 编写的基本脚本,它可以从命令行无限期地运行,从 Twitter 流 API 获取输入并用它做非常基本的事情。

我的最终目标是运行几个这样的进程(可能使用 系统守护进程 PEAR 类进行守护进程),我希望能够通过一些管理流程(也是 PHP 脚本)来管理它们。我所说的管理是指基本操作,例如停止/启动和(最重要的是)自动重新启动崩溃的进程。

对于如何最好地处理这个流程管理角度的任何指示,我将不胜感激。再次,如果这个问题过于广泛,我们深表歉意 - 如果有必要,我们将不胜感激有关更集中的调查线索的提示。感谢您的阅读,期待您的答复。

First off - hello, this is my first Stack Overflow question so I'll try my best to communicate properly.

The title of my question may be a bit ambiguous so let me expand upon it immediately:

I'm planning a project which involves taking data inputs from several "streaming" APIs, Twitter being one example. I've got a basic script coded up in PHP which runs indefinitely from the command line, taking input from the Twitter streaming API and doing very basic things with it.

My eventual objective is to have several such processes running (perhaps daemonized using the System Daemon PEAR class), and I would like to be able to manage them from some governing process (also a PHP script). By manage I mean basic operations such as stop/start and (most crucially) automatically restarting a process that crashes.

I would appreciate any pointers on how best to approach this process management angle. Again, apologies if this question is too expansive - tips on more tightly focused lines of enquiry would be appreciated if necessary. Thanks for reading and I look forward to your answers.

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

何止钟意 2024-09-03 21:12:36

我认为拥有持久进程的推荐方法根本不是在 PHP 中执行;)

但这里有一些相关的问题,看起来一些反馈包含一些好的想法和经验。

更多内容请参见 搜索

I think the recommended way of having persistent processes is not doing it in PHP at all ;)

But here are some related questions, it looks like some of the feedback contains some good thoughts and experience in doing this.

More in the search.

初相遇 2024-09-03 21:12:36

这在运行持久性 PHP 脚本的上下文中不起作用,但 Cron 对于在不同时间和不同时间间隔运行脚本确实很方便。您可以使用 Cron 以适当的时间间隔运行所有脚本,而不是让 PHP 脚本不断运行、停止和启动各种其他脚本。

This doesn't work in the context of running a persistent PHP script, but Cron is really handy for running scripts at different times and at different intervals. Instead of having a PHP script that is running constantly, stopping and starting various other scripts, you could run them all using Cron at a suitable interval.

如梦初醒的夏天 2024-09-03 21:12:36

您想要的方式是可能的,但会很复杂并且相对难以维护。

如果您以不同的方式看待它,您可以定期对数据进行分块,而不是连续地进行数据流处理。从技术上讲,它仍在流式传输,尤其是像 Twitter 这样的提要。

如果某些源是实时输出的,您可能会错过中间的一些数据,那么这可能不适合您。

管理启动和停止以及管理少量数据的进程要容易得多。他们都可以检查数据库中的控制数据并更新状态。而且,使用 cron 真的是一种乐趣。

这几天我就是这么做的。

The way you want to do it is possible but will be complex and relatively difficult to maintain.

If you look at it in a different way, instead of steaming continuously, you could be chunking in data at regular intervals. Technically its still streaming, especially with feeds like twitter.

If some feed is pumping out in real time, you may miss some data inbetween then maybe this is not an option for you.

Its far easier to manage processes that start and stop and which manage small amounts of data. They could all be checking a database for control data and updating the status. Also, using cron is a real pleasure.

That's how I would do it these days.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文