note 41514 deleted from function.fread by cmb
| From: | cmb@php.net | Date: | Sun, 12 Jan 2020 08:18:41 +0000 |
| Subject: | note 41514 deleted from function.fread by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-213846@lists.php.net to get a copy of this message | ||
Note Submitter: squeegee
----
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
}
?>