Starting/stopping phirehose via a web interface

209 views
Skip to first unread message

MrGlass

unread,
Aug 14, 2010, 9:08:33 PM8/14/10
to Phirehose Users
I am working on setting up a web controlled service that uses
phirehose to accumulate tweets, stick them in a DB, and then
asynchronously consume them. The client request specifically asked
that the service could be started/stopped via web interface.

The examples provided for both accumulating and consuming tweets are
infinite loops. I figure I can easily start them via an AJAX control,
but I cant figure out how I would tell them to stop. Is there an
established method?

Fenn Bailey

unread,
Aug 14, 2010, 9:20:23 PM8/14/10
to phireho...@googlegroups.com
Hey MrGlass,

Telling it when to stop should be fairly easy. You could just put a check in your implementation of checkFilterPredicates() that checks a common flag (say in a database or memcache) that tells it to keep running or not, ie, something like:
---
if ($this->getKeepRunning() != TRUE) {
  $this->disconnect();
  exit;
}
---

Where getKeepRunning() is some sort of (fast) check to see if the "keep running" flag is set. Keep in mind that checkFilterPredicates() is called every 5 seconds, so you want your check to be quick.

In terms of starting the server, that's actually harder than it may initially appear. Keep in mind (as per the documentation) that Phirehose is not designed to be run from inside a webserver (I'm not sure if you were intending to or not).

If you just start Phirehose from an AJAX request, it will only run until you hit PHP's maximum run time (usually only a 1-2 minutes) and then stop. To keep it running forever (ie: in an infinite loop), you need to run it as a separate, backgrounded process.

You can read some more about this in an previous discussion here:


Cheers!

  Fenn.

MrGlass

unread,
Aug 14, 2010, 9:51:44 PM8/14/10
to Phirehose Users
I guess I could have a service running that listens for a 'start'
command, and launch phirehose from that.

I don't need the actual service to start/stop via browser interface, I
just need it to start/stop collecting.

On Aug 14, 9:20 pm, Fenn Bailey <fenn.bai...@gmail.com> wrote:
> Hey MrGlass,
>
> Telling it when to stop should be fairly easy. You could just put a check in
> your implementation of checkFilterPredicates() that checks a common flag
> (say in a database or memcache) that tells it to keep running or not, ie,
> something like:
> ---
>
> if ($this->getKeepRunning() != TRUE) {
>   $this->disconnect();
>   exit;
>
> }
>
> ---
>
> Where getKeepRunning() is some sort of (fast) check to see if the "keep
> running" flag is set. Keep in mind that checkFilterPredicates() is called
> every 5 seconds, so you want your check to be quick.
>
> In terms of starting the server, that's actually harder than it may
> initially appear. Keep in mind (as per the documentation) that Phirehose is
> *not* designed to be run from inside a webserver (I'm not sure if you were
> intending to or not).
>
> If you just start Phirehose from an AJAX request, it will only run until you
> hit PHP's maximum run time (usually only a 1-2 minutes) and then stop. To
> keep it running forever (ie: in an infinite loop), you need to run it as a
> separate, backgrounded process.
>
> You can read some more about this in an previous discussion here:
>
> http://groups.google.com/group/phirehose-users/browse_thread/thread/c...
>
> Cheers!
>
>   Fenn.
Reply all
Reply to author
Forward
0 new messages