richardvc wrote:
The reason was a php script accessing GD to generate images on the fly.
richardvc wrote:
My questions is how can I limit the php or apache to use fix amount of CPU or RAM?
I can think of three options. All of them involve compromises of one sort or another.
1) Reduce the memory_limit in php.ini to something more reasonable, like 32M. But this will cause your image processing script to fail.
2) Reduce MaxClients (the maximum number of scripts that can run at the same time) to a very low value, so that you don't run out of RAM even if some scripts use a lot of RAM. But this can cause slowdowns if a lot of people access your site at the same time, because they'll queue up.
3) Get rid of that on-the-fly image processing script. Use a command-line script, cron job, background process, or some other non-web-accessible mechanism to process your images. But this requires some programming and sysadmin knowledge, may be difficult to integrate into an existing program, and may cause image generation to be delayed by a few seconds to a few minutes.
Image processing in PHP is extremely RAM-intensive. Ever since StackScripts more ore less solved the problem of default MaxClients being too high, most of the "I ran out of RAM!!!" threads in this forum have involved image processing in one way or another. You just can't keep doing it in real-time if you want to keep your precious RAM. You've gotta drop it, slow it down, or separate it into its own background job.