-1

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.

Community
  • 1
  • 1
navgeet
  • 987
  • 1
  • 10
  • 23
  • Is sysvmsg enabled? It is not a standard extension. http://php.net/manual/en/sem.installation.php – rrehbein Jul 13 '12 at 15:39
  • What's the code look like when you remove the message queues? – Mike Lively Jul 13 '12 at 17:39
  • @rrehbein: from phpinfo(), it seems sysvmsg is not enabled. Then what are my options for communicating between two php scripts. Specifically I want to pass a POST message from a form to the bot, and send the msg to the irc channel. – navgeet Jul 13 '12 at 17:54

1 Answers1

2

Based on your comment, your missing the extension.

If you have control of the machine, your can install the php-sysvmsg extension.

If not, then you may end up having to use tcp or udp as an "ipc", or named pipes.

The package names for sysvmsg:

  • RedHat/CentOS: yum install php-process
  • Debian: it is already included in php5-cgi and php5-cli
  • Zend Server/RedHat: yum install php-5.3-sysvmsg-zend-server
  • Zend Server/Debian: apt-get install php-5.3-sysvmsg-zend-server
rrehbein
  • 4,120
  • 1
  • 17
  • 23