开发者

Recommended way to manage persistent PHP script processes?

开发者 https://www.devze.com 2022-12-26 11:23 出处:网络
First off - hello, this is my first Stack Overflow question so I\'ll try my best to communicate properly.

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 line开发者_运维百科s of enquiry would be appreciated if necessary. Thanks for reading and I look forward to your answers.


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.

  • Is it wise to use PHP for a daemon?

  • Run php script as daemon process (especially 2nd and 3rd answer)

  • PHP Daemon/worker environment

More in the search.


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消