Hello Kirupians I have a problem that I would like some help with.
I am making an irc bot out of php that is suppose to grab every new line of text at the end of the file every time the txt file has a new line or a few lines of new text. My problem is everytime new text is added to a file it takes a while for php to get the text to irc. I need it to get input to irc as soon as the text file is updated. I don’t know if I should use Fgets and Fopen for the file or not.
If anyone knows the problem could you please help me fix it? Thanks
set_time_limit(0);
$socket = socket_create(AF_INET,SOCK_STREAM,SOL_TCP);
socket_connect($socket,'irc.com',6667);
socket_write($socket,"USER LWBOT2 For all of you
");
socket_write($socket,"NICK LWBOT2
");
socket_write($socket,"JOIN #LWBOT
");
$count = 0;
$start = 1;
$file = "echoin.txt";
while($data2 = file($file)) {
if ($data2 != "") {
$dat = $data2[$count];
}
$ecex = explode(' ', $dat);
if ($ecex[0] == "[JOIN]"){
socket_write($socket, "PRIVMSG #Brandon :".$ecex[1]." has joined the game
");
}
if ($ecex[0] == "[QUIT]"){
socket_write($socket, "PRIVMSG #Brandon :".$ecex[1]." has left the game
");
}
if ($count < count($data2) && ){
$count++;
}
}
while($data = socket_read($socket,2046))
{
echo $data;
flush();
$ex = explode(' ',$data);
if($ex[0] == "PING"){
socket_write($socket, "PONG ".$ex[1]."
");
}
if (strtolower($command) == ":!die") {
socket_close($socket);
die();
exit();
}
}