garbage.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. // Disable Compression
  3. @ini_set('zlib.output_compression', 'Off');
  4. @ini_set('output_buffering', 'Off');
  5. @ini_set('output_handler', '');
  6. /**
  7. * @return int
  8. */
  9. function getChunkCount()
  10. {
  11. if (
  12. !array_key_exists('ckSize', $_GET)
  13. || !ctype_digit($_GET['ckSize'])
  14. || (int) $_GET['ckSize'] <= 0
  15. ) {
  16. return 4;
  17. }
  18. if ((int) $_GET['ckSize'] > 1024) {
  19. return 1024;
  20. }
  21. return (int) $_GET['ckSize'];
  22. }
  23. /**
  24. * @return void
  25. */
  26. function sendHeaders()
  27. {
  28. header('HTTP/1.1 200 OK');
  29. if (isset($_GET['cors'])) {
  30. header('Access-Control-Allow-Origin: *');
  31. header('Access-Control-Allow-Methods: GET, POST');
  32. }
  33. // Indicate a file download
  34. header('Content-Description: File Transfer');
  35. header('Content-Type: application/octet-stream');
  36. header('Content-Disposition: attachment; filename=random.dat');
  37. header('Content-Transfer-Encoding: binary');
  38. // Cache settings: never cache this request
  39. header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0, s-maxage=0');
  40. header('Cache-Control: post-check=0, pre-check=0', false);
  41. header('Pragma: no-cache');
  42. }
  43. // Determine how much data we should send
  44. $chunks = getChunkCount();
  45. // Generate data
  46. if (function_exists('random_bytes')) {
  47. $data = random_bytes(1048576);
  48. } else {
  49. $data = openssl_random_pseudo_bytes(1048576);
  50. }
  51. // Deliver chunks of 1048576 bytes
  52. sendHeaders();
  53. for ($i = 0; $i < $chunks; $i++) {
  54. echo $data;
  55. flush();
  56. }