while($data = fgets($socket, 128)) { echo nl2br($data); $total = nl2br($data); flush(); $log = fopen('log.html', 'a'); fwrite($log, $total); fclose($log); }