Styles2304 Posted July 4, 2008 Share Posted July 4, 2008 I can't seem to find the loop that's eating up the memory. If anyone else can spot it . . . PLEASE . . .let me know. The Error: Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 33292335 bytes) in /home/styles/public_html/photosview.php on line 63 And the actual code: <?php //Checking for completion of thumb nail outputs while ($ThumbOutPut == 0) { //checking for existence of file while ($FileExists == 0) { $ThumbTest = 'galleries/' . $Directory . '/small/small_' . $Suffix . $ImageNumber . '.' . $Extension; if (file_exists($ThumbTest)) { $FileExists = 1; } else { $ImageNumber++; } } $FileExists = 0; //checks to see if this is the last image or not if ($ImageNumber == $LImage) { $ThumbOutPut = 1; } else { //checks to see if there are <td> elements yet and creates a new row if ($ThumbLineCounter == 5) { $ThumbNails .=<<<EOD </tr> <tr> EOD; $ThumbLineCounter = 0; } $ThumbNails .=<<<EOD <td valign="top" align="center"> <img src="$ThumbTest" border="0"> </td> //The EOD; Right after this is line 63 EOD; $ThumbLineCounter++; } } ?> If you guys notice anything . . . please point it out. Quote Link to comment https://forums.phpfreaks.com/topic/113186-solved-fatal-error-using-up-memory-suspect-a-loop/ Share on other sites More sharing options...
Daniel0 Posted July 4, 2008 Share Posted July 4, 2008 Your first loop runs infinitely, your second loop (nested within the first) also runs infinitely if the condition check within that loop is never met. You are using loops incorrectly. Exactly what are you trying to do? Quote Link to comment https://forums.phpfreaks.com/topic/113186-solved-fatal-error-using-up-memory-suspect-a-loop/#findComment-581544 Share on other sites More sharing options...
Styles2304 Posted July 4, 2008 Author Share Posted July 4, 2008 It doesn't run indefinitely . . . I set $ThumbOutPut to 1 once $ImageNumber is the same as $LImage (Last Image) The same with $FileExists. Quote Link to comment https://forums.phpfreaks.com/topic/113186-solved-fatal-error-using-up-memory-suspect-a-loop/#findComment-581710 Share on other sites More sharing options...
teynon Posted July 4, 2008 Share Posted July 4, 2008 Quick question, exactly how many files is it doing? The output could be huge? Try just outputting the information and seeing what that does. Quote Link to comment https://forums.phpfreaks.com/topic/113186-solved-fatal-error-using-up-memory-suspect-a-loop/#findComment-581715 Share on other sites More sharing options...
Styles2304 Posted July 4, 2008 Author Share Posted July 4, 2008 It's only 48 items . . . this is to populate a photo gallery. A step by step: 1.) Runs a loop to keep cycling through the images based on the number of the image. (while ($ThumbOutPut == 0)) 2.) Runs a loop to see if the file exists (while ($FileExists == 0 )) 3.) If the file is found, it sets $FileExists to 1 continues . . . then resets $FileExists for the next round. If it doesn't, it increases $ImageNumber and repeats 4.) Then, it checks to see if $ImageNumber is equal to $LImage which would mean that the program has found the last image. It sets $ThumbOutPut to 1 which should end the entire loop. If it hasn't, it continues with the code: 5.) It Then checks to see if there have been 5 images output in one row ($ThumbLineCounter). If it has, it creates a new row in the table, otherwise it creates a new column and outputs the image. Then increases $ThumbLineCounter by 1. I'll try it with like 2 images or something and see what happens. Quote Link to comment https://forums.phpfreaks.com/topic/113186-solved-fatal-error-using-up-memory-suspect-a-loop/#findComment-581724 Share on other sites More sharing options...
Styles2304 Posted July 4, 2008 Author Share Posted July 4, 2008 Ok . . . while only doing it with 3 images . . . it does the exact same thing. No idea. Quote Link to comment https://forums.phpfreaks.com/topic/113186-solved-fatal-error-using-up-memory-suspect-a-loop/#findComment-581727 Share on other sites More sharing options...
Styles2304 Posted July 4, 2008 Author Share Posted July 4, 2008 lol ehh . . . I forgot to increase ImageNumber at the end of the program . . . so uh yeah . . . solved! Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/113186-solved-fatal-error-using-up-memory-suspect-a-loop/#findComment-581731 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.