Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is acceptable memory usage for a PHP page? [closed]

Tags:

php

I'm building a webpage that queries a MySQL database and (currently) produces a text-only list of the findings. The queries to complete a single record are similar to:

  • movie (title, description, etc)
    • actors in the movie (name, gender)
    • related movies

Out of curiosity I've used memory_get_peak_usage() and memory_get_usage():

start   110,440 bytes
peak    656,056 bytes
end 637,976 bytes
time    0.008 seconds

The above is with no records found!

With 40 records I'm reaching approximately 2MB, though the time remains the same.

I know that premature optimization is evil and all, but I have to ask:

Do I need to do some reworking? Is this memory usage normal? What is considered excessive?

like image 595
bbxbby Avatar asked Oct 24 '08 06:10

bbxbby


3 Answers

Ultimately it's preferable to optimize when convenient of course, but 2MB of memory use sounds fine. PHP4 has a default config of 8mb, and PHP5 16mb. A lot of pre-packaged PHP builds will have different configs, of course, but generally speaking, if you can keep your app under 8mb, you can be sure it'll be highly portable in that regard.

like image 117
Owen Avatar answered Oct 24 '22 04:10

Owen


Obviously it all depends on the complexity of the application you're building. In average, the pages of our application take up to 20 MB (min) of memory. That's because there's a lot of objects in the session, and a lot of initialisation process that occur before the script can even say hello world (authentification, rights management, notifications, ...)

There's a lot of things that go in the memory space, including classes definitions, globals, function definitions, etc. Reducing the amount of loaded classes (by using auto-includes) is a good way to keep your scripts with only the necessary amount of classes definitions.

I don't know if loading up extensions changes the memory usage - that should be something to test, because by default we may not need all the default loaded extensions ?

like image 8
Bertrand Gorge Avatar answered Oct 24 '22 04:10

Bertrand Gorge


Personally I set the limit to 8 MB. If I exceed that I try to improve my application. The reason is because some shared hosts and PHP 4 configurations have the default limit of 8 MB per process.

like image 3
Tower Avatar answered Oct 24 '22 03:10

Tower