Jump to content


Photo

memory and gd library


  • Please log in to reply
4 replies to this topic

#1 Drongo_III

Drongo_III

    Advanced Member

  • Members
  • PipPipPip
  • 512 posts

Posted 12 September 2013 - 02:33 PM

Hello

I have recently been working with gd library as part of an image upload system. I noticed that one of my scripts was failing due to exceeding the available memory.

Anyway researching this I discovered that gd library can be quite memory hungry and the pixel width height of even a small image can require a lot of memory - even when the file size is quite low.

So my question is how do really big sites deal with this? If u have a high volume upload form for instance I could imagine the drain in memory being quite massive.

So do they just throw hardware at it or are there more efficient image libraries than gd?

Incidentally I corrected the memory issue by changing the ini setting for the script. Just in case anyone has that problem.
Learning something new simply uncovers how much there is left to learn...

One day when I know what I'm talking about all my noob posts will come back to haunt me. But I shall rejoice in the cleansing light of knowledge over ignorance :)

#2 kicken

kicken

    Wiser? Not exactly.

  • Gurus
  • 2,651 posts
  • LocationBonita, FL

Posted 12 September 2013 - 04:23 PM

So my question is how do really big sites deal with this? If u have a high volume upload form for instance I could imagine the drain in memory being quite massive.


Handle the image operations external to PHP. For instance, exec() out to ImageMagick or similar. PHP's memory limits and other restrictions do not apply to external processes. Such programs may also have better optimizations and do the job quicker.
Recycle your old CD's, don't trash them!
Did I help you out?  Feeling generous? I accept tips via Paypal or Bitcoin @ 14mDxaob8Jgdg52scDbvf3uaeR61tB2yC7

#3 Drongo_III

Drongo_III

    Advanced Member

  • Members
  • PipPipPip
  • 512 posts

Posted 12 September 2013 - 05:24 PM

Handle the image operations external to PHP. For instance, exec() out to ImageMagick or similar. PHP's memory limits and other restrictions do not apply to external processes. Such programs may also have better optimizations and do the job quicker.

 

 

I am interested in understanding this better so apologies if I'm being slow. When you say use exec do you mean to execute a program on an external server? How would using exec on the same server get around the issue of using up memory since the server resource will be used just the same?  Sorry i realise this is all a bit abstract but I can foresee a time in the future when I'll need to build something similar for a much higher volume website so I'd like to understand a  good approach.


Learning something new simply uncovers how much there is left to learn...

One day when I know what I'm talking about all my noob posts will come back to haunt me. But I shall rejoice in the cleansing light of knowledge over ignorance :)

#4 kicken

kicken

    Wiser? Not exactly.

  • Gurus
  • 2,651 posts
  • LocationBonita, FL

Posted 12 September 2013 - 08:29 PM

You could farm the processing out to a dedicated machine (or multiple machines) if the need was there. Until you hit a massive scale though, just running the process on the same machine would suffice. PHP limits it's own memory consumption. Just because you hit a limit in PHP does not mean that the system cannot do more. If you do reach a point at which the system is overloaded then yes, the answer is just "throw hardware at it" by adding additional servers, either as dedicated image processors, or just additional web servers to distribute the load.
Recycle your old CD's, don't trash them!
Did I help you out?  Feeling generous? I accept tips via Paypal or Bitcoin @ 14mDxaob8Jgdg52scDbvf3uaeR61tB2yC7

#5 Drongo_III

Drongo_III

    Advanced Member

  • Members
  • PipPipPip
  • 512 posts

Posted 13 September 2013 - 02:09 AM

Thanks mate that's brill. :)
Learning something new simply uncovers how much there is left to learn...

One day when I know what I'm talking about all my noob posts will come back to haunt me. But I shall rejoice in the cleansing light of knowledge over ignorance :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com