Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 <?php | |
| 2 header_remove("X-Powered-By"); | |
| 3 | |
| 4 $redirect = (bool) $_GET["redirect"]; | |
| 5 $cached = (bool) $_GET["cached"]; | |
| 6 $chunked = (bool) $_GET["chunked"]; | |
| 7 $size = (int) $_GET["size"]; | |
| 8 $gzip = (bool) $_GET["gzip"]; | |
| 9 $flush_header_with_x_bytes = (int) $_GET["flush_header_with_x_bytes"]; | |
| 10 $wait_after_headers_packet = (int) $_GET["wait_after_headers_packet"]; | |
| 11 $flush_every_x_bytes = ((int) $_GET["flush_every"])?:1; | |
| 12 $wait_every_x_bytes = ((int) $_GET["wait_every_x_bytes"])?:0xFFFFF; | |
| 13 $wait_duration_every_x_bytes = ((int) $_GET["wait_duration_every_x_bytes"])?:50; | |
| 14 | |
| 15 $sent_data_size = 0; | |
| 16 | |
| 17 if ($redirect) { | |
| 18 unset($_GET["redirect"]); | |
| 19 header("Location: ?" . http_build_query($_GET)); | |
| 20 exit; | |
| 21 } | |
| 22 | |
| 23 // This is done because it should force netstack to handle data as it comes. | |
| 24 header("Content-Type: application/json"); | |
| 25 | |
| 26 if ($cached) { | |
| 27 header("HTTP/1.0 304 Not Modified"); | |
| 28 exit; | |
| 29 } | |
| 30 | |
| 31 if ($gzip) | |
| 32 ob_start("ob_gzhandler"); | |
| 33 else | |
| 34 ob_start(); | |
| 35 | |
| 36 if (!$chunked) | |
| 37 header("Content-Length: " . $size); | |
| 38 | |
| 39 if ($flush_header_with_x_bytes) { | |
| 40 send_data($flush_header_with_x_bytes); | |
| 41 full_flush(); | |
| 42 } | |
| 43 | |
| 44 if ($wait_after_headers_packet) | |
| 45 usleep($wait_after_headers_packet * 1000); | |
| 46 | |
| 47 while ($sent_data_size < $size) { | |
| 48 $flush_size = $flush_every_x_bytes - ($sent_data_size % $flush_every_x_bytes ); | |
| 49 $wait_size = $wait_every_x_bytes - ($sent_data_size % $wait_every_x_bytes); | |
| 50 | |
| 51 $send_size = min($flish_size, $wait_size); | |
|
Nico
2017/05/11 16:58:20
This is probably supposed to be flush_size, not fl
| |
| 52 if (!$send_size) | |
| 53 $send_size = max($flish_size, $wait_size); | |
| 54 | |
| 55 send_data($send_size); | |
| 56 if ($sent_data_size % $flush_every_x_bytes === 0) | |
| 57 full_flush(); | |
| 58 if ($sent_data_size % $wait_every_x_bytes === 0) | |
| 59 usleep($wait_duration_every_x_bytes * 1000); | |
| 60 } | |
| 61 | |
| 62 function send_data($size) | |
| 63 { | |
| 64 global $sent_data_size; | |
| 65 echo str_repeat("a", $size); | |
| 66 $sent_data_size += $size; | |
| 67 } | |
| 68 | |
| 69 function full_flush() | |
| 70 { | |
| 71 ob_flush(); | |
| 72 flush(); | |
| 73 } | |
| OLD | NEW |