-
Notifications
You must be signed in to change notification settings - Fork 1
/
pjstreamer.php
49 lines (46 loc) · 1.39 KB
/
pjstreamer.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
/**
* @author Manujith Pallewatte [[email protected]]
* @date 11/11/13
* PHP class to stream realtime php to javascript through AJAX
* Can also be used to show realtime php output on the browser
*/
class PJStreamer{
/**
* Setup the necessary switches to make the server have realtime output behaviour
*/
public static function startStream(){
try{
//try to change the server functions first
// Turn off output buffering
ini_set('output_buffering', 'off');
// Turn off PHP output compression
ini_set('zlib.output_compression', false);
// Implicitly flush the buffer(s)
ini_set('implicit_flush', true);
}catch(Exception $e){
}
//Flush (send) the output buffer and turn off output buffering
while (@ob_end_flush());
ob_implicit_flush(true);
//now add browser tweaks
echo str_pad("",1024," ");
echo "<br />";
ob_flush();
flush();
sleep(1);
}
/**
* Function to send the content to be streamed, adding special end character
* @param $out ANY
* Any kinda output
*/
public static function sendStream($out){
//send the output
echo $out;
//flush just to be sure
ob_flush();
flush();
}
}
?>