Advertisement
Guest User

Untitled

a guest
Sep 27th, 2013
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.17 KB | None | 0 0
  1. <?php
  2.     // Oddly, passing in any parameter into a URL causes PHP to use LESS memory...
  3. echo memory_get_usage(true) . "<br />\n";
  4.     $idmap = array();
  5.     $rows2 = array("_1" => array(), "_2" => array(), "_3" => array(), "_4" => array(), "_5" => array(), "_6" => array(), "_7" => array());
  6.     for ($x = 0; $x < 5000; $x++)
  7.     {
  8.         $idmap[$x] = array("test1");
  9.         $row2 = array("A decent length string." . htmlspecialchars("A decent length string.") . "A decent length string.", $x);
  10.         $options = array();
  11.         $options[] = "A decent length string." . htmlspecialchars("A decent length string.") . "A decent length string.";
  12.         $options[] = "A decent length string." . htmlspecialchars("A decent length string.") . "A decent length string.";
  13.         $options[] = "A decent length string." . htmlspecialchars("A decent length string.") . "A decent length string.";
  14.         $options[] = "A decent length string." . htmlspecialchars("A decent length string.") . "A decent length string.";
  15.         $options[] = "A decent length string." . htmlspecialchars("A decent length string.") . "A decent length string.";
  16.         $options[] = "A decent length string." . htmlspecialchars("A decent length string.") . "A decent length string.";
  17.         $row2[] = implode(" | ", $options);
  18.  
  19.         $rows2["_6"][] = $row2;
  20.     }
  21.  
  22.     // About 10MB RAM here with real-world data (the above is about 8MB with the test data - close enough?).
  23. echo memory_get_usage(true) . "<br />\n";
  24.  
  25.     $rows = array();
  26.     foreach ($rows2 as $key => $rows3)
  27.     {
  28.         foreach ($rows3 as $num => $row)
  29.         {
  30.             // This occasionally (i.e. randomly) leaks memory like crazy in here (> 128MB),
  31.             // despite the exact same data being passed in on the URL *AND* the exact same data in $rows2.
  32.             $row[1] = htmlspecialchars(implode(", ", $idmap[$row[1]]));
  33.             $rows[] = $row;
  34.  
  35.             // Even weirder, adding a simple if-statement here that does absolutely nothing causes the leak to disappear...
  36. //if ($_SERVER["REMOTE_ADDR"] != "")
  37. //{
  38. //}
  39. echo memory_get_usage(true) . "<br />\n";
  40.         }
  41.     }
  42.  
  43.     // About 20MB RAM here with real-world data...whenever the foreach() code above doesn't run wild.
  44. echo memory_get_usage(true) . "<br />\n";
  45. echo "Peak: " . memory_get_peak_usage(true) . "<br />\n";
  46. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement