How exactly do I keep Phirehose open running as a background process? If every user on my site can open a stream to Twitter API throughout their entire logged in session (I know this won't scale well but it must be done for the beginning phase), how to I maintain a PHP script to run in the background all the while?
I could see forking a process with a C++ program and having that run as a daemon, but how does one keep a PHP fsocket stream open?
I understand how to use this API, how it works, how to collect开发者_如何学运维 and consume messages, but not sure how to keep it up and running
Phirehose: https://github.com/fennb/phirehose
Phirehose should run indefinitely if started as its own PHP process - ie: It should never exit by itself unless something goes wrong. The only usual reason it should stop is if it disconnects too many times (or otherwise gets connection errors).
php-cli does not honour the *set_time_limit()* param, so you don't need to worry about that if you're using a CLI SAPI. You can test which SAPI your binary is by running php -v:
$ php -v PHP 5.2.10-2ubuntu6.4 with Suhosin-Patch 0.9.7 (cli) (built: May 10 2010 14:33:52) Copyright (c) 1997-2009 The PHP Group Zend
If the process doesn't appear to keep running, check the log output, which should describe why & what's going on.
Also, Twitter only permits a single connection per user, so if you're trying to connect multiple times with the same username, this could be causing the disconnections.
Good luck!
If you want a PHP script to keep running then call set_time_limit()
with a very very long time (or keep calling it every now and then before the time runs out). And then simply make sure not to exit the script and it will keep running until you say otherwise.
精彩评论