I needed a simple php IRC bot that takes messages through POST requests and sends that message to an irc channel. For this purpose I adapted the bot from PHP - IRC Bot Not sending message Help. Then I used message queues to send the POST message to the bot from IRC related help.
However when I run the php script through start.html, the bot doesn't even join the channel. irc.php ->
<?php
$ircServer = "irc.freenode.net";
$ircPort = "6667";
$ircChannel = "##my-channel";
set_time_limit(0);
$ircSocket = fsockopen($ircServer, $ircPort, $eN, $eS);
$msg = $_POST['msg'];
if ($ircSocket)
{
fwrite($ircSocket, "USER EDI Normandy-SR2 Alliance Dr-Eva\n");
fwrite($ircSocket, "NICK Hit-Hi-Fit-Hai\n");
fwrite($ircSocket, "JOIN " . $ircChannel . "\n");
fwrite($ircSocket, "PRIVMSG $ircChannel :$msg\n");
$queueKey = 123321;
$queue = false;
// Join the IPC queue
$queue = msg_get_queue($queueKey);
if(!$queue) echo "ERROR: Could not join IPC queue. Form data will not be received";
while(1)
{
while($data = fgets($ircSocket, 128))
{
echo nl2br($data);
flush();
$ex = explode(' ', $data);
if($ex[0] == "PING") fputs($socket, "PONG ".$ex[1]."\n");
if (msg_receive($queue, 0, $msgType, 1024, $msgData, true, MSG_IPC_NOWAIT)) {
//fwrite($ircSocket, "PRIVMSG $ircChannel :$msgData\n");
echo "callback working";
}
}
}
}
?>
Hers's how I am calling this script. start.html ->
<html><body>
<h4>Start Bot</h4>
<form action="irc.php" method="post">
Command: <input type="text" name="msg" />
<input type="submit" />
</form>
</body></html>
If I remove the code for message queues, the bot does join the channel.