-
IRC Bot
Hi guys,
I've started making a bot in php (run from the command line) for IRC. I am finding it fairly simple to do what i want except one thing. How do i stop my script from terminating once it has executed? I can connect to an IRC server and join channels but once there is nothing for the bot to do it just terminates. Any ideas for a main loop? OR are there any existing modules that do this?
Thanks in advance!
-
Re: IRC Bot
Not sure that PHP is the right language for this; it is not very good at event-driven programming. You will hit the maximum execution time if you have a loop; although you can alter that setting, it's still not an ideal platform for such an application.
-
Re: IRC Bot
OK... I may have a go in C. Having said that, how would i go about a php scripting interface for a C program.
-
Re: IRC Bot
Um, why?
What is this, a web application or a command line application?
-
Re: IRC Bot
Command line PHP scripts don't have an execution time limit, I think. Nothing wrong with doing this in PHP.
-
Re: IRC Bot
It is a command line application... And I don't think that is correct. Once i execute the script i can see that the bot has joined but then it disconnects once the script reach its end. I think PERL would be much more suited to this. But if i can do it in PHP that would be fantastic.
-
Re: IRC Bot
Well, the script should block on reading messages, not just end.
-
Re: IRC Bot
yeah... so... it's not reading messages all the time, so as soon as it is idle it exits.
-
Re: IRC Bot
Well, then you need to make it wait until a message is available. How do you read messages in the first place?
-
Re: IRC Bot
socket_read()? problem is i haven't got that far. There is not point working out how i'm gonna read new messages if i can't get the thing to stay alive.
-
Re: IRC Bot
Of course there is! Reading new messages is the key to staying alive. socket_read() will block until data is available, keeping your program alive. Then you process the data, act on it, and start over.
Code:
while(running) {
data = read data;
process data into messages;
for every message {
if message is control command {
respond to message;
}
if message is quit command {
running = false;
}
}
}