Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Okay here's a better answer. The first section still stands. A new PHP process is called every time you want to initiate a new script. Thus, you need some way to do IPC.</p> <p>Here's how it's done on *nix (but not windows) in PHP:</p> <p><strong>Receiver:</strong></p> <pre><code>&lt;?php $queueKey = 123321; $queue = false; if(msg_queue_exists($queueKey)) { echo "Queue Exists.\n"; } // Join the queue $queue = msg_get_queue($queueKey); while(!($queue == false)) { // Note: This function could block if you feel like threading $msgRec = msg_receive( $queue, // I: Queue to get messages from 0, // I: Message type (0 = first on queue) $msgType, // O: Type of message received 1024, // I: Max message size $msgData, // O: Data in the message true, // I: Unserialize data MSG_IPC_NOWAIT // I: Don't block ); if($msgRec) { echo "Message received:\n"; echo "Type = $msgType\n"; echo "Data = \n"; print_r($msgData); } } ?&gt; </code></pre> <p><strong>Sender:</strong></p> <pre><code>&lt;?php $queueKey = 123321; $queue = false; if(msg_queue_exists($queueKey)) { echo "Queue Exists.\n"; } else { echo "WARNING: Queue does not exist. Maybe no listeners?\n"; } $queue = msg_get_queue($queueKey); $abc["something"] = "something value"; $abc["hello"] = "world"; $abc["fu"] = "bar"; msg_send( $queue, // Queue to send on 1, // Message type $abc, // Data to send true, // Serialize data? true // Block ); ?&gt; </code></pre> <p>This should produce (in the receiver loop) something similar to this:</p> <pre><code>Message received: Type = 1 Data = Array ( [something] =&gt; something value [hello] =&gt; world [fu] =&gt; bar ) </code></pre> <p>Your script might look something like this</p> <p>postToMe.php:</p> <pre><code>&lt;?php $queueKey = 123321; $queue = false; if(msg_queue_exists($queueKey)) { echo "Queue Exists.\n"; } else { echo "WARNING: Queue does not exist. Maybe no listeners?\n"; } $queue = msg_get_queue($queueKey); msg_send( $queue, // Queue to send on 1, // Message type $_POST, // Data to send true, // Serialize data? true // Block ); ?&gt; </code></pre> <p>bot.php:</p> <pre><code>&lt;?php set_time_limit(0); $socket = fsockopen("//", 6667) or die(); $msg = $_POST['message']; $pr = $_POST['percentage']; $pr /= 100; fputs($socket,"USER BOT 0 zo :ZH bot\n"); // Set the bots nickname fputs($socket,"NICK BOT1\n"); fputs($socket,"JOIN #bots\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) { // Handle new post info // You may want to increase the message size from 1024 if post data is large if(msg_receive($queue, 0, $msgType, 1024, $msgData, true, MSG_IPC_NOWAIT)) { // Handle data here. Post data is stored in $msgData } while($data = fgets($socket, 128)) { // echo the data received to page echo nl2br($data); // flush old data, it isn't needed any longer. flush(); $ex = explode(' ', $data); if($ex[0] == "PING") fputs($socket, "PONG ".$ex[1]."\n"); $search_string = "/^:([A-Za-z0-9_\-]+)[@!~a-zA-Z0-9@\.\-]+\s*([A-Z]+)\s*[:]*([\#a-zA-Z0-9\-]+)*\s*[:]*([!\#\-\.A-Za-z0-9 ]+)*/"; $do = preg_match($search_string, $data, $matches); // check that there is a command received if(isset($matches['2'])) { switch($matches['2']) { case "PRIVMSG": $user = $matches['1']; $channel = $matches['3']; $chat_text = isset($matches['4']) ? $matches['4'] : ""; // check chat for !time if(strtolower($chat_text) == "!time") { $output = "::::: " . date('l jS \of F Y h:i:s A') . " :::::"; fputs($socket, "PRIVMSG " . $channel . " :" . $output . "\n"); } elseif(strtolower($chat_text) == "!hello") { fputs($socket, "PRIVMSG " . $channel . " :Hello!\n"); } break; case "JOIN": $user = $matches['1']; $channel = $matches['3']; fputs($socket, "PRIVMSG " . $channel . " :Welcome " . $user . " to " . $channel . "\n"); break; } } } } ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload