PHP Bot timeout
Posted: Thu May 04, 2006 4:39 pm
I've written several PHP bots that work well on my server (where i can play with ping times and such) I'm having an issue connecting to a remote IRC server. The script keeps timing out during periods of low traffic.
I've set my "set_time_limit" to 0 to prevent PHP from timing out the session, wich it does, however after 60 seconds, my browser times out the connection causing the bot to disconnect. I Fixed this at home by creating a class with a 50 second ping time. I do not have this option available to me on this remote server.
What work arounds do i have available?
here is the start of my connection code
I've set my "set_time_limit" to 0 to prevent PHP from timing out the session, wich it does, however after 60 seconds, my browser times out the connection causing the bot to disconnect. I Fixed this at home by creating a class with a 50 second ping time. I do not have this option available to me on this remote server.
What work arounds do i have available?
here is the start of my connection code
Code: Select all
//setting server side stuff.
set_time_limit(0);
//ICR server settings
$server = "someremote.host";
$room = "#room";
$port = "6667";
//Nickname stuff
$botname = "PHPBot";
$nickservpass = "XXXXXX";
############################### Start of script ################################
$serv = fsockopen($server,$port);
//Part of hte IRC protocol requires certain steps in order to connect.
//We are doing these manualy here
fputs($serv,"USER ".$botname." localhost localhost :".$botname."\r\n");
fputs($serv,"NICK ".$botname."\r\n");
while ($line = fgets($serv,1024)) {
$a = explode(" ", $line);
$a[2] = strtolower($a[2]);
//This echo is to debug the program. since the script is run with output to
// /dev/null, there is no need to comment this out.
echo "<= $line <br />";
flush();
switch ($a[0]) {
//the ping/pong reponse is a requirement, if the bot idles too long
//the server will ping the client, a pong needs to be sent back to keep
//the connection alive. this is done here.
case "PING":
fputs($serv, "PONG ".$a[1]." \r\n");
echo "=> PONG ".$a[1]."<br>";
break;
default:
break;
}