<?php $host="irc.freenode.net"; $channel="#testGiggs"; $connect=fsockopen($host,6667, $errno, $errstr, 30); //* Specify the reference variables holding the error string and number; Give a timeout (30 seconds) for the socket if(!$connect) { //* Use the NOT (!) to check for a FALSE return ($connect will return FALSE if an error occurs) echo "Error! $errstr ($errno)"; //* Handle the error } else { while(!feof($connect)) { //* Using the !feof tells the script to loop through the received content(from the $connect socket resource) until the end of the stream is found (generally the closing of the socket) //* $handle=fopen($host,"r"); This shouldn't be needed. $data=rtrim(fread($connect, 2000)); //* Adding an rtrim to the data will remove the \r\n's from the inbound data; These can cause problems when trying to use the data echo $data; //* ."\r\n"; You're echoing the data back to STDOUT (your command line); So the \r\n is not required here. } }?>