I'm trying to read a streaming data using PHP.
So I would like to read and show every message posted from a server in real time.
I assume that $uri, $context from the code snipped are correctly defined.
When I use this code, the only result I got is when then lenght is reached. It seams that it doesnt stop on delimiter "" string.
DEFINE('TOKEN', "MY_TOKEN");
$opts = array(
'http' => array(
'method' => "GET",
'header'=> "Authorization: Basic " . base64_encode(TOKEN)));
$context = stream_context_create($opts);
if (($fp = fopen($uri, "r", false, $context))) {
while (!feof($fp)) {
$contents = stream_get_line($fp, 1024, "");
echo "text: " . $contents . "
";
}
fclose($fp);
When the lenght is reached, it show correctly all the new messages posted. with the string "text: " before every message.
How could I do to print one message by one ?
PS: I tried to use "", " ", " " or " ", nothing works :/.
I need some help there, thanks a lot.
Edit: adding the context