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 doFlush(); | |
| 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 if ($flush_size === $wait_size) { | |
|
Adam Rice
2016/09/01 08:57:28
This seems a bit convoluted. How about
send_data(
allada
2016/09/07 06:01:12
Done.
| |
| 51 send_data($flush_size); | |
| 52 doFlush(); | |
| 53 usleep($wait_duration_every_x_bytes * 1000); | |
| 54 } else if ($flush_size < $wait_size) { | |
| 55 send_data($flush_size); | |
| 56 doFlush(); | |
| 57 } else { | |
| 58 send_data($wait_size); | |
| 59 usleep($wait_duration_every_x_bytes * 1000); | |
| 60 } | |
| 61 } | |
| 62 | |
| 63 function send_data($size) | |
| 64 { | |
| 65 global $sent_data_size; | |
| 66 echo str_repeat("a", $size); | |
| 67 $sent_data_size += $size; | |
| 68 } | |
| 69 | |
| 70 function doFlush() | |
| 71 { | |
| 72 ob_flush(); | |
| 73 flush(); | |
| 74 } | |
| OLD | NEW |