coderofsalvation / browser-stream
stream text to browser in realtime without using websockets or ajax.
Installs: 300
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
pkg:composer/coderofsalvation/browser-stream
Requires
- php: >=5.4.0
This package is not auto-updated.
Last update: 2020-01-14 11:31:37 UTC
README
Stream text to browser in realtime without using websockets. Think simple text progressbars, logging, longrunning tasks, terminal output etc.Usage
$ composer require coderofsalvation/BrowserStream
and then
<?php
use coderofsalvation\BrowserStream;
BrowserStream::enable();
BrowserStream::put("loading");
for( $i = 0; $i < 10; $i++ ){
BrowserStream::put(".");
sleep(1);
}
?>
Now go to your browser and you'll see 'loading' and dots being added every second OH MY! :)
Test it with curl like so:
$ curl -H "Accept: text/event-stream" -N -s "http://localhost/foo.php"
Apache Gzip == no worky
Usually apache gzips the output of php. This is not good if you want realtime output. Therefore disable apache gzip buffering in .htaccess for a particular (realtime streaming) url like so:
RewriteRule ^(yoururl)$ $1 [NS,E=no-gzip:1,E=dont-vary:1]
License
BSD