2017 © Pedro Peláez
 

library browser-stream

stream text to browser in realtime without using websockets or ajax.

image

coderofsalvation/browser-stream

stream text to browser in realtime without using websockets or ajax.

  • Wednesday, August 19, 2015
  • by coderofsalvation
  • Repository
  • 2 Watchers
  • 0 Stars
  • 79 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 4 % Grown

The README.md

BrowserStream

, (*1)

Stream text to browser in realtime without using websockets. Think simple text progressbars, logging, longrunning tasks, terminal output etc., (*2)

Usage

$ composer require coderofsalvation/BrowserStream 

and then, (*3)

    <?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! :), (*4)

, (*5)

Test it with curl like so:, (*6)

$ 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:, (*7)

    RewriteRule ^(yoururl)$ $1 [NS,E=no-gzip:1,E=dont-vary:1]

License

BSD, (*8)

The Versions

19/08 2015

dev-master

9999999-dev

stream text to browser in realtime without using websockets or ajax.

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.4.0