views:

55

answers:

3

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.

+1  A: 

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.

Pekka
That's super - the second link you posted did indeed yield many useful links! Researching now. Thanks for your input :).
BigglesZX
+1  A: 

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.

Sam152
Depending on requirements, this is a good approach. You can also use this to monitor an ongoing process; check every minute if it's still running and automatically restart if it fails. Depends how much downtime you can take, but it it's reading feeds, then every minute sounds fine.
El Yobo
A: 

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.

zaf