Php 通道内的IRC联机计数

Php 通道内的IRC联机计数,php,html,irc,Php,Html,Irc,我发现一个脚本有问题。有时有效有时无效。。。有人看到它有什么问题吗?还是有更好的 非常感谢 <?php /* CONFIGURATIONS! */ $irc_server = 'xxxxxxxxxx'; // Server $irc_port = '6667'; // Port //$irc_nick = ''; // Nick $irc_channel = '#xxxxxxxx'; // Channel /* END CONFIGURAT

我发现一个脚本有问题。有时有效有时无效。。。有人看到它有什么问题吗?还是有更好的

非常感谢

<?php 
/* CONFIGURATIONS! */ 
$irc_server = 'xxxxxxxxxx';  // Server 
$irc_port = '6667';             // Port 
//$irc_nick = '';   // Nick 
$irc_channel = '#xxxxxxxx';     // Channel 
/* END CONFIGURATIONS! */ 

$socket = fsockopen($irc_server,$irc_port);            // Connect to the server. 
fputs($socket,"USER SOCKS SOCKS SOCKS :SOCKS\r\n");    // Send the username. 
fputs($socket,"NICK $irc_nick \r\n");                  // Set our nick. 
fputs($socket,"LIST $irc_channel \r\n");               // List the provided channel. 

// $handle = fopen('log.txt',a);  // Log if you want. 

// Set initial value. 
$users = 0; 

// Receive the incoming data. 
while(1) { 
    $sock_data = fgets($socket,1024);   // Get each line of data from the response. 
    // fwrite($handle,"$sock_data\r\n");   // Write the log. 

    // Get the information section of the desired responses. 
    $sep = explode(':',$sock_data);  // Separate by colons. 
    $info = $sep[1];  // After the first colon is the important information. 
    $message = $sep[2]; 

    // Break down the response and get the id and who sent it. 
    $info_sep = explode(' ',$info);  // Separate by spaces. 
    $full_who = $info_sep[0];  // The person who sent it is the first item in the list. 
    $id = $info_sep[1];  // The id is the second item in the list. 
    $who_sep = explode('!',$full_who);  // Separate by exclamation points. 
    $who = $who_sep[0];  // The nick of the person is the part before the exclamation point. 

    // I saw some scripts checking for this, so... 
    if ($who == 'PING') { 
        fputs($socket,"PONG $message"); 
    } 

    // PRIVMSG indicates someone is sending you a message. 
    // We just need this to reply to the VERSION and PING requests. 
    if ($id == 'PRIVMSG') { 
        if (substr($message, 0, 8) == 'VERSION') {  // Reply to the version response. 
        fputs($socket,"NOTICE $who :".chr(1)."VERSION getUsers v0.1b".chr(1)."\r\n"); 
        } elseif (strstr($message, 'PING') !== false) {  // Ping them back if needed. 
            fputs($socket,"NOTICE $who :$message"); 
        } 
    } 

    // 322 is the list response. 
    // This should get the number of users on the provided channel. 
    if ($id == '322') { 
        $users = $info_sep[4];  // The number of users. 
        // fclose($handle);  // Close the log. 
        fclose($socket);  // Close the connection. 
        break;  // End the loop. 
    } 

    // 323 is the end list response. 
    // This is in case there is no 322 response (the channel doesn't exist, maybe?) 
    if ($id == '323') { 
        // fclose($handle);  // Close the log. 
        fclose($socket);  // Close the connection. 
        break;  // End the loop. 
    } 

    // 263 is the failed response. 
    // Wait 2 seconds and retry. 
    if ($id == '263') { 
        sleep(2);  // Pause for 2 seconds. 
        fputs($socket,"LIST $irc_channel \r\n");  // List the provided channel. 
    } 
} 

// Display the results on the page. 
if ($users == '1') { 
    echo "1"; 
} else { 
    echo "$users"; 
}
?>

您可能会更幸运地使用一个经过测试且稳定的PHP IRC库,如PEAR的Net_SmartIRC-

您能更具体一点吗?你期待什么样的行为?什么不起作用?它在什么条件下工作或不工作?