SitePoint Sponsor

User Tag List

Results 1 to 12 of 12
  1. #1
    SitePoint Addict goldensona's Avatar
    Join Date
    Jun 2011
    Posts
    226
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Memory problem in php

    Hi

    i want to know about how the php handle memory allocation, if i use the oops concept how the allocated object memory will free ,it will automatically , can any one tell about this. how we use effective memory utilization in php.

  2. #2
    I solve practical problems. bronze trophy
    Michael Morris's Avatar
    Join Date
    Jan 2008
    Location
    Knoxville TN
    Posts
    2,015
    Mentioned
    62 Post(s)
    Tagged
    0 Thread(s)
    PHP doesn't allow you to directly access the memory. You can monitor memory consumption during the script and use unset to manually clear variables you know you aren't going to use, though PHP's garbage collection will wipe these eventually anyway. Your question does raise the red light of "are you sure PHP is the language to use for this?" because memory management is typically the last consideration of most PHP scripts, and some of the most popular are veritable pigs with memory (here's looking at you Magento).

  3. #3
    SitePoint Zealot 2ndmouse's Avatar
    Join Date
    Jan 2007
    Location
    West London
    Posts
    196
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This has worked for me in the past:

    PHP Code:
    ini_set("memory_limit","-1"); 
    Detect file changes remotely. SimpleSiteAudit is an early
    warning anti-hacker system which sends an alert on detection.

    PHP Find Orphan Files - Finds all the unreferenced files on your site.

  4. #4
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    69 Post(s)
    Tagged
    0 Thread(s)
    ew. Good way to have your server overload.
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  5. #5
    Always A Novice bronze trophy
    K. Wolfe's Avatar
    Join Date
    Nov 2003
    Location
    Columbus, OH
    Posts
    2,178
    Mentioned
    63 Post(s)
    Tagged
    2 Thread(s)
    Might be worth reading: http://www.tuxradar.com/practicalphp/18/1/10

    Most of my scripts use a recursion that uses that same variables over and over again. Most operations done in PHP aren't dealing with objects large enough to have a significant impact on your memory usage. There is a garbage collection function as of 5.3 something, though, which i have yet to find the need to use yet.

  6. #6
    SitePoint Zealot 2ndmouse's Avatar
    Join Date
    Jan 2007
    Location
    West London
    Posts
    196
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, fair point - maybe '-1' is a bit drastic, but it could be used with a specific value:

    PHP Code:
    ini_set("memory_limit","50mb"); 
    Detect file changes remotely. SimpleSiteAudit is an early
    warning anti-hacker system which sends an alert on detection.

    PHP Find Orphan Files - Finds all the unreferenced files on your site.

  7. #7
    SitePoint Addict goldensona's Avatar
    Join Date
    Jun 2011
    Posts
    226
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by 2ndmouse View Post
    Ok, fair point - maybe '-1' is a bit drastic, but it could be used with a specific value:

    PHP Code:
    ini_set("memory_limit","50mb"); 
    if i use 50mb in limit, i can use only 50mb if my application want to user more than that what will happen, i want to make sure if i didnt unset the unused variable,mysql free result it will automatically clear when the script end ,my understanding is correct ?. else it will raise memory problem.

  8. #8
    SitePoint Zealot 2ndmouse's Avatar
    Join Date
    Jan 2007
    Location
    West London
    Posts
    196
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ini_set()
    Sets the value of the given configuration option. The configuration option will keep this new value during the script's execution, and will be restored at the script's ending.
    quoted from PHP.net so you don't need to worry about unsetting.

    ini_set("memory_limit","50m"); sets an upper limit of 50mb - you need to know roughly what your upper limit is for this to work satisfactorily.
    Detect file changes remotely. SimpleSiteAudit is an early
    warning anti-hacker system which sends an alert on detection.

    PHP Find Orphan Files - Finds all the unreferenced files on your site.

  9. #9
    SitePoint Addict goldensona's Avatar
    Join Date
    Jun 2011
    Posts
    226
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    ok thanks for your suggestion. i dont want to specify by setting,whether php manage automatic garabage collection , while doing code i have to do memory release ?

  10. #10
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    69 Post(s)
    Tagged
    0 Thread(s)
    What exactly are you doing that would require more than 50 MB of memory usage? o.O
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  11. #11
    I solve practical problems. bronze trophy
    Michael Morris's Avatar
    Join Date
    Jan 2008
    Location
    Knoxville TN
    Posts
    2,015
    Mentioned
    62 Post(s)
    Tagged
    0 Thread(s)
    Large image manipulation - that's all I've got. That or he's running Magento.

  12. #12
    SitePoint Addict goldensona's Avatar
    Join Date
    Jun 2011
    Posts
    226
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    just i want to know about it .


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
  •