SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Enthusiast
    Join Date
    Jun 2003
    Location
    Ljubljana, Slovenia
    Posts
    83
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP memory usage .. win XP vs. Linux

    here is the deal ..

    For 6 months now .. I've been working on a really big PHP application suported by other Java applications.. lets just say my PHP application handles the web distribution and the administration of the whole sistem..

    but .. I was developing on my home machine .. winXP athlon 64, apache 2 and php 5.. I uploaded the application and started testing on a main server .. 4 Gigs of ram .. a disk array .. apache 2 and php5 .. and ran into a big problem ...

    scripts consumed more than 8 Megs of ram ... on my comp the same script ran on default PHP.ini settings and on the big sistem I had to change to 32 megs for script to work ..

    anybody ran into the same problem ..

    btw .. the database was the same .. the data from the databse was the same .. everything was the same from the data point of view .. I just cant figure out why 4 times more memory usage !?

    any ideas would be appreciated ..

    Bye

    Armando

  2. #2
    SitePoint Wizard HarryR's Avatar
    Join Date
    Dec 2004
    Location
    London, UK
    Posts
    1,376
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Have you considered that perhaps memory limits were disabled on your Windows development machine? (e.g. it wasn't compiled with --enable-memory-limit for whichever reason) - but on the production machine it was.

    The easiest way to check for this would probably be to try to use memory_get_usage() ( http://docs.php.net/en/function.memory-get-usage.html ).

    If memory limits are enabled - it'll tell you how much memory you're currently using, if not - it'll probably throw up an error.

    To be honest 32mb really does sound like quite a lot per-client, which I guess could cause problems with scalability (lets not go into that here).

    If you're using something like Zend Studio or another PHP IDE with good debugging integration, you should be able to setup a watch that gets the value of memory_get_usage() - so while you're stepping through you can see memory usage in near real-time.

  3. #3
    SitePoint Enthusiast
    Join Date
    Jun 2003
    Location
    Ljubljana, Slovenia
    Posts
    83
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    10x for info ..
    will check it out ..
    On win machine is the defult PHP installation .. with some changes in PHP ini ..

    bye

    Armando

  4. #4
    SitePoint Zealot
    Join Date
    Feb 2003
    Posts
    156
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Unless you compile your own php binaries on windows, you won't have the memory-limit enabled. I don't know why, but that's the way it goes. I was actively searching for something like that and couldn't find anything, I ended up installing Ubuntu (which I am very happy with).

    Anyway, if you want to work on your memory problems, you should develop or test on a machine that has php binaries with memory-limit enabled. Then you can use the xdebug extension to check what parts of the code are responsible for the most memory usage.

    Typical cases will be:
    - a very large codebase. If you are including very many files with several thousands LOC, this will consume quiet a bit of memory. Solution: See if you can split up your files (especially templates, language files etc.) and only include what you really need. You can also install an opcode cache, however that will only help w/ respect to scalability, because initially the scripts have to be loaded and processed at least once.
    - reading in lots of data from the database, and storing it in variables, that will later get processed. Solution: Process the data row by row, and store only that which you reall need.
    - first creating lots of (large) objects, then rendering their output. Solution: If possible, let each object be rendered right after creation, and then unset() the variable, before going to the next one.
    - Using many output buffers, if the default buffer size is pretty large. Solution: Use a smaller buffer size, if possible. Sometimes the generated pages themselves are very large: If you show a list of several hundred items with many nested table, the generated page itself may weigh more than a Megabyte. THen you should break up the page (for the sake of usability that's a good idea) into several smaller ones, and let the user page between them.

    The other option is of course to just change the php configuration, if you are not expecting many concurrent users, this won't be a problem. And adding RAM may be the cheaper option...

  5. #5
    SitePoint Enthusiast
    Join Date
    Jun 2003
    Location
    Ljubljana, Slovenia
    Posts
    83
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    10x for advice .. and thank you for telling me that the WIN php does not support memory limits .. its a good idea .. but since this is a framework I'm working on .. it would be really foobared if I had to change everything for cosuming less space .. but anyhow .. thanks for the tips appreciate it !!!

    bye

    Armando

  6. #6
    SitePoint Addict
    Join Date
    Apr 2002
    Posts
    330
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by armandoxxx
    scripts consumed more than 8 Megs of ram ... on my comp the same script ran on default PHP.ini settings and on the big sistem I had to change to 32 megs for script to work ..
    This is normal, especially if you use MySQL because mysql_query buffers result sets in memory. Actually if it grows up to 20MB it will not be surprising.

    Anyway, since a great part of the script memory usage is spent on compilation, you may want to consider using a caching extension like Turck, despite it will not make it take less 10MB all by itself.
    Manuel Lemos

    Metastorage - Data object relational mapping layer generator
    PHP Classes - Free ready to use OOP components in PHP


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •