-1

I have a very long PHP script adapting multiple images and creating many arrays. At a certain moment I get the Fatal error: Allowed memory size of X bytes exhausted error at a very random line:

if (isset($pixels[$x1+1][$y1+1])) return Array($x1+1,$y1+1);

So I know the problem is not really this line. What I want to do is somehow print the amount of memory exhausted already at several places throughout my script, so I can optimize my code to exhaust less and so I can see which code blocks are really memory-intensive. To do so I would need something like:

echo $memorySizeUsed."<br />";

Is there a way to do so, or do I have to dig just randomly?

Charles
  • 50,010
  • 13
  • 100
  • 141
JohannesB
  • 1,865
  • 21
  • 33

1 Answers1

1

Use memory_get_usage() to monitor memory usage:

echo "memory usage: " . memory_get_usage () . " bytes";
hek2mgl
  • 143,113
  • 25
  • 227
  • 253