You are here: Re: 100KB image that takes up 2mb of memory uses up all 8mb of memory - help! « PHP Programming Language « IT news, forums, messages
Re: 100KB image that takes up 2mb of memory uses up all 8mb of memory - help!

Posted by comp.lang.php on 09/26/06 01:31

Andy Hassall wrote:
> On 25 Sep 2006 13:41:02 -0700, "comp.lang.php" <phillip.s.powell@gmail.com>
> wrote:
>
> >I have an image that's only 100K in size, and I am working with 8mb of
> >memory. If I do this:
> >
> >[PHP]
> >print_r(ceil((int)ini_get('memory_limit') * 10 *
> >filesize(actual_path("$locationPath/$this->fileName")) / 1000000) .
> >'M'); // PRINTS OUT "2M" for 2mb
> >]/PHP]
>
> Maybe I'm having a dense moment, but what does this value even mean?
> memory_limit times 10 times size of file then divided by a million?
>
> Is the output actually "2M" ? If you have a 100,000 byte file, doesn't that
> mean your memory_limit is set to "2" ? (presumably "2M", turning into "2" after
> the cast to int).
>

Ok I'll make it super simple because I have to explain it so that I
understand. I want to increase memory because "8M" is 8mb which for
some images is not enough memory to run imagecreatefromjpeg, or
imagecreatefromgif or imagecreatefrompng.. so I am going to increase it
from 8MB to something like "130mb" or "130M" if need be for very large
images. It works every time, even if it's an eventual bad idea.

However, this image is 87KB in size and if I use the same formula to
"increase memory", instead I "decrease memory instead"

> >The image itself requires far less than the maximum amount of memory
> >required.
> >
> >However, the moment I do this:
> >
> >[PHP]
> > $imagestring =
> >@file_get_contents(actual_path(realpath("$locationPath/" .
> >$this->{$section . '_name'})));
> >[/PHP]
> >
> >It locks up and forces a download of "index.php" (which indicates to me
> >that the memory allotment of 8mb has been used up).
>
> That seems like a guess... what error messages do you get? If you can't see
> them, change the content-type of the output back to text.

I see no errors not even in the PHP error log, absolutely nothing is
logged. Tried changing content-type to text/plain, to no avail, still
force-downloads index.php

>
> >How in the world can a 100KB image that uses only 2mb of 8mb use up 8mb
> >of memory on file_get_contents() alone? I'm completely confused!
>
> Why would a 100KB image use 2MB? Where did 8MB come from? I'm also confused...

Sorry but I have no idea whatsoever. Can someone else elaborate?
>
> The usual pitfall is that a 100KB image can easily decompress to several
> megabytes, and that GD uses even more memory than you might expect.
>
> --
> Andy Hassall :: andy@andyh.co.uk :: http://www.andyh.co.uk
> http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация