When using feof() on a TCP stream, i found the following to work (after many hours of frustration and anger):
NOTE: I used ";" to denote the end of data transmission. This can be modified to whatever the server's end of file or in this case, end of output character is.
<?php
$cursor = "";
$inData = "";
while(strcmp($cursor, ";") != 0) {
$cursor = fgetc($sock);
$inData.= $cursor;
}
fclose($sock);
echo($inData);
?>
Since strcmp() returns 0 when the two strings are equal, it will return non zero as long as the cursor is not ";". Using the above method will add ";" to the string, but the fix for this is simple.
<?php
$cursor = "";
$inData = "";
$cursor = fgetc($sock);
while(strcmp($cursor, ";") != 0) {
$inData.= $cursor;
}
fclose($sock);
echo($inData);
?>
I hope this helps someone.