Page 1 of 1

Help with fsockopen

Posted: Tue Mar 03, 2009 11:13 am
by Cirdan
Never mind...it was because I was returning 0 at the end...which is equal to false :P.

I am using MAMP, and am trying to use fsockopen to connect to an IRC server to receive the number of users in the channel. But I am getting error number 0, with no error string. No PHP errors.

hostname = 76.107.162.100
port = 11111

Code: Select all

    // Returns the number of users in the IRC
    // Returns false if failed
    private function _getIrcCount()
    {
        
        $socket = fsockopen($this->_hostname, $this->_ircPort, $error_num, $error_str, 30);
        
        echo $error_num.' '.$error_str;
        if(!$socket)
            return false;
            
        stream_set_timeout($socket, 1);
        fwrite($socket, "nick robot\nuser b b b b\nnames #redeemed\nquit\n");
        
        $buffer = "";
        
        while(!feof($socket))
            $buffer .= fgets($socket, 16);
            
        fclose($socket);
        
        if (preg_match ('/= #redeemed <!-- s:( --><img src=\"{SMILIES_PATH}/icon_sad.gif\" alt=\":(\" title=\"Sad\" /><!-- s:( -->.*)\s*\n/', $buffer, $matches))
        {
            $output = $matches[1];
            $output = preg_replace("/\s+$/", "", $output);
        }
        else
        {
            $output = 0;
        }
        
        return $output;
    }