note 41514 added to function.fread

From: Date: Tue, 13 Apr 2004 09:25:11 +0000
Subject: note 41514 added to function.fread
Groups: php.notes 
Request: Send a blank email to php-notes+get-68057@lists.php.net to get a copy of this message
fread also works for fsockopen's that are open-ended (no feof) if you know how the last packet for a particular set of data should end. For example, if you sent a command to an nntp server, the reply from the server would end with a dot and a carriage return/linefeed. The connection still stays open for more commands, but doing it this way is more efficient than doing line-by-line fgets until you get to the end of the reply. <?php if(($res=nntp_cmd($conn,"BODY $msgid",222))===false){ continue; }else{ $contents=''; while(1){ $packet=fread($conn,8192); $contents.=$packet; if(substr($packet,-3)==".\r\n")break; } // do something with $contents } ?> ---- Manual Page -- http://www.php.net/manual/en/function.fread.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+41514 Delete -- http://master.php.net/manage/user-notes.php?action=delete+41514&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+41514&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#68057) next »