Jump to content

PHP 'Allowed memory size' odd error


richrock

Recommended Posts

I'm having real difficulty with something that should simply work...  :wtf:

 

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...  :o

 

Yet this fails - any help  :confused:

Link to comment
https://forums.phpfreaks.com/topic/212435-php-allowed-memory-size-odd-error/
Share on other sites

I'm having real difficulty with something that should simply work...  :wtf:

 

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...  :o

 

Yet this fails - any help  :confused:

 

Maybe an image name/size messes up the loop and makes it run over and over again until it fills up the memory?

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!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.