1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

doubt about memory_get_usage. more memory being allocated?

Discussion in 'PHP' started by downloadsonline.org, Oct 10, 2011.

  1. #1
    Hi,
    As shown at : http://php.net/manual/en/function.memory-get-usage.php
    I ran this script on my site :

    <?php
    // This is only an example, the numbers below will
    // differ depending on your system
    
    echo memory_get_usage() . "\n"; // 36640
    
    $a = str_repeat("Hello", 4242);
    
    echo memory_get_usage() . "\n"; // 57960
    
    unset($a);
    
    echo memory_get_usage() . "\n"; // 36744
    
    ?>
    Code (markup):
    and the result is :
    319400
    340776
    319480

    Compared to the example on the PHP site, memory usage for the script on my site is very high?

    why is this so ?
    Is there anything I should do to reduce memory usage?

    Please reply if you would like to know more info.

    Thank you
     
    downloadsonline.org, Oct 10, 2011 IP
  2. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #2
    There's too many factors to answer this. If php is running via apache which is fairly common, it would be expected to have much higher memory usage than if it is running as cgi. Also, if you have a ton of php modules compiled with php, the memory usage would be much higher by default.
     
    jestep, Oct 11, 2011 IP
  3. Rainulf

    Rainulf Active Member

    Messages:
    373
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    85
    #3
    I've never had mine that high before. There must be something running that you are not aware of, or leaking or who knows what's happening on your site. If you have root access, try to restart your server and see if it makes a difference. Try also to upgrade your PHP to the latest, if you have not done.
     
    Rainulf, Oct 11, 2011 IP
  4. JohnnySchultz

    JohnnySchultz Peon

    Messages:
    277
    Likes Received:
    4
    Best Answers:
    7
    Trophy Points:
    0
    #4
    maybe you can check the settings of your php ini, maybe your server's memory_limit is different from what the example stated.

    jestep has a point, your server might have more modules loaded that's why you have a higher memory usage
     
    JohnnySchultz, Oct 12, 2011 IP
  5. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #5
    On one of my production servers:

    50968
    72320
    51096

    On localhost (a bigger machine, with more RAM):

    322976
    344280
    322976

    Same server/PHP installation on both.

    I wouldn't lose any sleep over it.
     
    Rukbat, Oct 14, 2011 IP