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.

[How to] set different memory_limit value only in a file

Discussion in 'PHP' started by basketmen, Feb 21, 2011.

  1. #1
    Hi guys,

    in WHM >> PHP Configuration Editor (php.ini) >> the memory_limit are set to 30M, so the server no need too high resource, and to prevent poorly written scripts for eating up all available memory on a server

    I want a file only, lets say some.php, that already trusted of course, get higher memory_limit more than set in php.ini


    is there any way to do that?
     
    basketmen, Feb 21, 2011 IP
  2. TimK

    TimK Peon

    Messages:
    51
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    
    $newSize='50M';
    ini_set('memory_limit', $newSize);
    
    PHP:
    Obviously changing $newSize too what is required is up to you.
     
    TimK, Feb 21, 2011 IP
  3. basketmen

    basketmen Well-Known Member

    Messages:
    837
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    130
    #3
    i am sorry, where to add that?

    in the php file, or in php.ini file in whm?
     
    basketmen, Feb 21, 2011 IP
  4. ThePHPMaster

    ThePHPMaster Well-Known Member

    Messages:
    737
    Likes Received:
    52
    Best Answers:
    33
    Trophy Points:
    150
    #4
    The PHP file
     
    ThePHPMaster, Feb 21, 2011 IP
  5. basketmen

    basketmen Well-Known Member

    Messages:
    837
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    130
    #5
    so it is looks like this? :



    
    <?php
    $newSize='50M';
    ini_set('memory_limit', $newSize);
    
    
    
    ?>
    
    PHP:
     
    basketmen, Feb 21, 2011 IP
  6. ThePHPMaster

    ThePHPMaster Well-Known Member

    Messages:
    737
    Likes Received:
    52
    Best Answers:
    33
    Trophy Points:
    150
    #6
    Yep, ini_set function 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.

    http://php.net/manual/en/function.ini-set.php
     
    ThePHPMaster, Feb 21, 2011 IP
  7. TimK

    TimK Peon

    Messages:
    51
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Thanks for taking that over PHPMaster, well explained. Obviously the variable isn't necessary and you could just fill it into the functions parameter as you normally would but I felt like it would be easier than explaining it.
     
    TimK, Feb 21, 2011 IP