-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathObTool.php
62 lines (46 loc) · 1.39 KB
/
ObTool.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
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
namespace Ling\Bat;
/**
* The ObTool class.
*/
class ObTool
{
public static function cleanAll($returnContent = false)
{
if (false === $returnContent) {
while (ob_get_level()) {
ob_get_clean();
}
} else {
$s = "";
while (ob_get_level()) {
$s .= ob_get_clean();
}
return $s;
}
}
public static function writeWithoutBuffering(callable $printCallable){
// https://www.binarytides.com/php-output-content-browser-realtime-buffering/
// Turn off output buffering
ini_set('output_buffering', 'off');
// Turn off PHP output compression
ini_set('zlib.output_compression', false);
//Flush (send) the output buffer and turn off output buffering
//ob_end_flush();
while (@ob_end_flush()) ;
// Implicitly flush the buffer(s)
ini_set('implicit_flush', true);
ob_implicit_flush(true);
//prevent apache from buffering it for deflate/gzip
// header("Content-type: text/plain");
header('Cache-Control: no-cache'); // recommended to prevent caching of event data.
for ($i = 0; $i < 1000; $i++) {
echo ' ';
}
@ob_flush();
@flush();
call_user_func($printCallable);
@ob_flush();
@flush();
}
}