php - stream_get_line dont read line as it arrives -


i'm trying read streaming data using php.

so read , show every message posted server in real time.

i assume $uri, $context code snipped correctly defined.

when use code, result got when lenght reached. seams doesnt stop on delimiter "\r" 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, "\r");     echo "text: " . $contents . "\n";   } fclose($fp); 

when lenght reached, show correctly new messages posted. string "text: " before every message.

how print 1 message 1 ?

ps: tried use "\r", "\n", "\n\r" or "\r\n", nothing works :/.

i need there, lot.

edit: adding context


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -