Professional Web Applications Themes

memory allocation problems in PHP and how to optimize? - PHP Development

PHP keeps throwing out-of-memory errors on me. By default PHP only allows a script 8 megs of memory. I want to know why my script has gotten so out-of-control when it comes to memory use. I'm assuming there must be some array somewhere that is bloating up with information, perhaps information that I assumed was being detroyed. It could be a rather small mistake, causing a big problem. But how does one debug memory allocation in PHP? There is no way, that I'm aware of, to see the memory usage of all variables at all times. Even if I had ...

  1. #1

    Default memory allocation problems in PHP and how to optimize?

    PHP keeps throwing out-of-memory errors on me. By default PHP only
    allows a script 8 megs of memory. I want to know why my script has
    gotten so out-of-control when it comes to memory use. I'm assuming
    there must be some array somewhere that is bloating up with
    information, perhaps information that I assumed was being detroyed. It
    could be a rather small mistake, causing a big problem. But how does
    one debug memory allocation in PHP? There is no way, that I'm aware
    of, to see the memory usage of all variables at all times.

    Even if I had the patience to hit every variable in all my code with
    var_dump(), just to get a rough estimate of their sizes, that still
    wouldn't help, because the moment the var goes over 8 megs, it
    crashes, before var_dump would have the time to print the info to me.
    lawrence Guest

  2. #2

    Default Re: memory allocation problems in PHP and how to optimize?

    lawrence wrote:
    > PHP keeps throwing out-of-memory errors on me. By default PHP only
    > allows a script 8 megs of memory.
    [...]


    check memory_get_usage()



    maybe put it in a function:

    <?php
    function debug_memory($reason) {
    echo $reason, ': ', memory_get_usage();
    }
    ?>

    and then call it before/after selected instructions

    <?php
    $a = $b; debug_memory('array copy');

    $b = NULL; debug_memory('NULLified array');
    ?>


    HTH

    --
    I have a spam filter working.
    To mail me include "urkxvq" (with or without the quotes)
    in the subject line, or your mail will be ruthlessly discarded.
    Pedro Guest

  3. #3

    Default Re: memory allocation problems in PHP and how to optimize?

    Pedro <hexkidhotpop.com> wrote in message news:<bmi3q1$mv5s7$2ID-203069.news.uni-berlin.de>...
    > lawrence wrote:
    > > PHP keeps throwing out-of-memory errors on me. By default PHP only
    > > allows a script 8 megs of memory.
    > [...]
    >
    >
    > check memory_get_usage()
    Outstanding. I searched on Google and came up with nothing. Thanks
    much, this will make debugging much easier.
    lawrence Guest

Similar Threads

  1. #40701 [NEW]: Memory allocation error
    By michaeldaly at magma dot ca in forum PHP Bugs
    Replies: 25
    Last Post: April 25th, 07:56 PM
  2. How do i adjust memory allocation on mac osx for Freehand MX ??
    By James Noon in forum Macromedia Freehand
    Replies: 2
    Last Post: December 18th, 09:14 PM
  3. Mapping a session to an allocation of virtual memory
    By Zev Berezin in forum Informix
    Replies: 1
    Last Post: August 3rd, 11:06 AM
  4. Replies: 2
    Last Post: July 25th, 01:27 PM
  5. Private Sort Memory Allocation Problem
    By Tim.D in forum IBM DB2
    Replies: 1
    Last Post: June 28th, 03:52 AM

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
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139