richrock Posted September 3, 2010 Share Posted September 3, 2010 I'm having real difficulty with something that should simply work... I've got a script that reads files within a specific folder defined elsewhere. Then it returns the filenames (image files) to an array. Relatively simple, you'd think... Here's the process loop : // Read directory for images @$dh = opendir($img_dir); while (false !== (@$filename = readdir($dh))) { if (($filename == '.') || ($filename == '..') || ($filename == 'Thumbs.db')) { } else { $files[] = $filename; } } There is a maximum of 4 images in each folder. This process will run once per page load. I have checked my php settings: memory_limit 256M post_max_size 64M upload_max_filesize 62M (just for good measure). IMHO 256m works for another site I developed which processes up to three images using imagemagick, and I've tested this with a 4mb png file too.... Yet I get this error : Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 35 bytes) in F:\html\bishopstrings\components\com_content\views\article\tmpl\default.php on line 43 This is telling me it's trying to allocate 35bytes when there is 268435456 bytes available... Yet this fails - any help Link to comment https://forums.phpfreaks.com/topic/212435-php-allowed-memory-size-odd-error/ Share on other sites More sharing options...
laanes Posted September 3, 2010 Share Posted September 3, 2010 I'm having real difficulty with something that should simply work... I've got a script that reads files within a specific folder defined elsewhere. Then it returns the filenames (image files) to an array. Relatively simple, you'd think... Here's the process loop : // Read directory for images @$dh = opendir($img_dir); while (false !== (@$filename = readdir($dh))) { if (($filename == '.') || ($filename == '..') || ($filename == 'Thumbs.db')) { } else { $files[] = $filename; } } There is a maximum of 4 images in each folder. This process will run once per page load. I have checked my php settings: memory_limit 256M post_max_size 64M upload_max_filesize 62M (just for good measure). IMHO 256m works for another site I developed which processes up to three images using imagemagick, and I've tested this with a 4mb png file too.... Yet I get this error : Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 35 bytes) in F:\html\bishopstrings\components\com_content\views\article\tmpl\default.php on line 43 This is telling me it's trying to allocate 35bytes when there is 268435456 bytes available... Yet this fails - any help Maybe an image name/size messes up the loop and makes it run over and over again until it fills up the memory? Link to comment https://forums.phpfreaks.com/topic/212435-php-allowed-memory-size-odd-error/#findComment-1106802 Share on other sites More sharing options...
laanes Posted September 3, 2010 Share Posted September 3, 2010 What are the @'s standing for in your code? @$dh = opendir($img_dir); while (false !== (@$filename = readdir($dh))) Link to comment https://forums.phpfreaks.com/topic/212435-php-allowed-memory-size-odd-error/#findComment-1106803 Share on other sites More sharing options...
wildteen88 Posted September 3, 2010 Share Posted September 3, 2010 Lannes: The @ symbol is used for error suppression. richrock: For your script to consume 256MB of memory or more, I guess you have an infinity loop issue. What is line 43 in default.php? Link to comment https://forums.phpfreaks.com/topic/212435-php-allowed-memory-size-odd-error/#findComment-1106808 Share on other sites More sharing options...
richrock Posted September 3, 2010 Author Share Posted September 3, 2010 Yes, it's an inifinity loop problem.... Line 43 is : $files[] = $filename; I've tried this: $dh = opendir($img_dir) or die('Not found!'); exit; And it's errored saying it can't find the folder, so I guess it's the wrong filepath. I'll check that out and go from there. Cheers! Link to comment https://forums.phpfreaks.com/topic/212435-php-allowed-memory-size-odd-error/#findComment-1106809 Share on other sites More sharing options...
richrock Posted September 3, 2010 Author Share Posted September 3, 2010 Yup - stoopid filepaths Thanks a lot for your help there! Link to comment https://forums.phpfreaks.com/topic/212435-php-allowed-memory-size-odd-error/#findComment-1106811 Share on other sites More sharing options...
wildteen88 Posted September 3, 2010 Share Posted September 3, 2010 Before using opendir check that the directory exists using is_dir. There ab example in the documentation for how to use opendir Link to comment https://forums.phpfreaks.com/topic/212435-php-allowed-memory-size-odd-error/#findComment-1106812 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.