i am trying to write a little patch for phpfreechat i am running with some friends.
I would like to have some kind of out of band messaging, like wall on a unix machine

In particular i have a monitor daemon running on the server that sometimes will write a single line of text to a file. What i would want is for that line of text to be read from the file (via a fopen/fread/exec of tail/whatever, this can change and is not the topic of the question) and be sent to all clients that are connected upon their next post, just like normal messages are.I figured out the $_SESSION method for checking if a given message had already been sent, but i can seem to find no straightforward way of doing this.
Where would be the best place to inject this message?
I looked inside the commands/getnewmsg.class.php but noticed that the $js structure that is populated requires some real ids and timestamps that, if not generated correctly, will cause the javascript client to refuse them and not display the message.
I am looking also inside the notice.class but there seems to be anyway some kind of restriction,or maybe i am not doing something correctly.
Can someone please provide a pointer or any idea?
thanks a lot in advance!
EDIT:
i might have found a promising way: i modified the getnewmsg.class file and added:
$toInjectMsg = getTheMessageSomehow();
if (strcmp($_SESSION['injectmsg'],$toInjectMsg) != 0) {
$container->write($recipient,$m_sender,"send",$toInjectMsg);
$_SESSION['injectmsg'] = $toInjectMsg;
}
this works fine, the only problem is i get as many notices as the number of connected clients. How can i be assured that each message is sent only once?
EDIT:
a little more work on that.
Was i was doing - am doing - is implementing an out of band transport for IRC

I found the ii software being most suited to this task
http://tools.suckless.org/ii/
since it exposes a very simple interface: for each thing you would have some kind of conversation with in a normal client (say irssi) you get a named unix pipe, one for output named out e and one for the input creatively called in.
As of the current situation i tested the program with some modification (php side only, i would really like to touch the ii code the least possible) and i was able to correctly send messages that were sent in the webchat to a given irc channel by having ii register and mantain the connession as a client of the chatroom, phpfreechat only had to write "username: <msg>" to the "in" pipe of the process for the message to be relayed. Of course there is no nick support in place, all messages that go in the webchat will appear coming from the user ii is using to connect to the channel, but since i hooked inside the log proxy i found that state, name changes and connection/disconnection of clients in the webchat are all relayed to irc reliably.
For the other direction i had a small modification of the php getnewmsg class to read one line from the ii's "out" stream each time it is invoked, deduping it's own messages or it will loop endlessly spamming both the irc channel and the chat, and then saving the last read line in the session, so to propagate it only once to the webchat via a
$container->write($recipient,"NAME","getnewmsg",$tobesent);
where NAME is the name of the fake webchat user relaying messages to the webchat room and $tobesent the message just read from irc.
This worked _great_ as it propagated irc joins, name changes etc to the webchat, BUT!
if the irc client were to die, for any reason, the read from the out buffer would always be the same last line - no problems there - but the write to the in pipe would become blocking, breaking completely the webchat. SO what i was going for was having the write fail with a timeout (can php do that?) and/or use the stream_set_blocking to set the write to nonblocking and compare the return value: if less than expected, restart the ii process (that would need some instrumentation but it can easily be added i guess) or inject a message signaling the irc transport is dead and have the users restart it (or trigger a script, or whatever).
Since i do not know php very well is there any other sensible way of solving the problem?
DISCLAIMER: this is an HORRENDOUS way of doing things, of course, there are security issues, code style and cleanliness problem, heavy coupling and so on, but this was just a quick hack to finally give this chat a feature i feel very important (and a quick search reveals i'm not the only one) and that is missing: a way of communicating to perhaps THE best chat network around.
So any comment, suggestion or insult is welcome.
thanks for reading so far
