Click to See Complete Forum and Search --> : IRC Bot
INV-Predator
Oct 22nd, 2006, 02:04 AM
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!
penagate
Oct 22nd, 2006, 07:46 AM
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.
INV-Predator
Oct 23rd, 2006, 03:23 AM
OK... I may have a go in C. Having said that, how would i go about a php scripting interface for a C program.
penagate
Oct 23rd, 2006, 04:03 AM
Um, why?
What is this, a web application or a command line application?
CornedBee
Oct 23rd, 2006, 06:49 AM
Command line PHP scripts don't have an execution time limit, I think. Nothing wrong with doing this in PHP.
INV-Predator
Oct 24th, 2006, 02:41 AM
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.
CornedBee
Oct 24th, 2006, 03:42 AM
Well, the script should block on reading messages, not just end.
INV-Predator
Oct 24th, 2006, 04:05 AM
yeah... so... it's not reading messages all the time, so as soon as it is idle it exits.
CornedBee
Oct 24th, 2006, 04:12 AM
Well, then you need to make it wait until a message is available. How do you read messages in the first place?
INV-Predator
Oct 24th, 2006, 04:24 AM
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.
CornedBee
Oct 24th, 2006, 04:28 AM
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.
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;
}
}
}
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.