SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Addict
    Join Date
    Mar 2007
    Posts
    286
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    php memory limit

    What is the best way to up the amount of memory used by php. I have checked on my server and its alright to do it. I think it can be done by placing my own php.ini file in the directory or through .htaccess. My questions are if I override php.ini do I have to specify all directives or will just the ones I create get overridden? Would it be better to do it through .htaccess? If so how?

  2. #2
    SitePoint Wizard bronze trophy Kailash Badu's Avatar
    Join Date
    Nov 2005
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    only those settings in php.ini will get overridden that are specified in .htaccess. The rest will remain as they are in php.ini.

  3. #3
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    or, you could use ini_set() to change the memory allowance for the duration that the script is running only.
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  4. #4
    SitePoint Addict
    Join Date
    Mar 2007
    Posts
    286
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Kailash Badu View Post
    only those settings in php.ini will get overridden that are specified in .htaccess. The rest will remain as they are in php.ini.
    Are you saying it is better to use .htaccess? Does the same thing apply if I don't use .htaccess and put a php.ini file in my directory. Where do I find the command to set the memory in .htaccess?

  5. #5
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Most hosts don't allow the use of .htaccess to do that kind of thing.

    it's much easier to just put:
    PHP Code:
    ini_set('memory_limit','16M'); 
    Rather than changing the configuration file.
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  6. #6
    SitePoint Addict
    Join Date
    Mar 2007
    Posts
    286
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by arkinstall View Post
    Most hosts don't allow the use of .htaccess to do that kind of thing.

    it's much easier to just put:
    PHP Code:
    ini_set('memory_limit','16M'); 
    Rather than changing the configuration file.
    Mine does and I would rather set it up in either php.ini or htaccess. Just feels more stable to me to do it one of these ways.

  7. #7
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    in which case, in your .htaccess:
    Code:
    php_value memory_limit 16M
    replace 16M with the wanted memory limit.

    Test it out by calling php_info(); before and after changing the .htaccess file.
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  8. #8
    Twitter - @CarlBeckel busy's Avatar
    Join Date
    May 2004
    Location
    Richmond, VA, USA
    Posts
    819
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by leonglass View Post
    What is the best way to up the amount of memory used by php. I have checked on my server and its alright to do it. I think it can be done by placing my own php.ini file in the directory or through .htaccess. My questions are if I override php.ini do I have to specify all directives or will just the ones I create get overridden? Would it be better to do it through .htaccess? If so how?
    If you are set up to use custom php.ini files, you only need to specify the directives that will be overridden, but unlike htaccess files you need to put a copy in each directory that you will be executing scripts from. For example if your site is in domain.com/ and you also have a section domain.com/admin/ you will need another custom php.ini file in the admin/ directory or your settings won't be used for those scripts.

    Also, I've noticed that scripts that need more memory than the default sometimes also require max_execution_time to be set a little higher, depending on what you're doing.


    Also, since you haven't used a custom php.ini before, here's a helpful bit I use in all of mine, to turn off errors in the browser, turn up your error level to include notices, and log all of them in a textfile.
    Code:
    error_reporting  =  E_ALL
    display_errors = Off
    log_errors = On
    error_log = /your_local_dir/logs/php_error.log
    Make sure the directory where you put the logfile exists.

    Hope this helps!

  9. #9
    SitePoint Addict
    Join Date
    Mar 2007
    Posts
    286
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by busy View Post
    ...
    Hope this helps!
    Yes it does thanks.
    Quote Originally Posted by arkinstall View Post
    php_value memory_limit 16M
    Just been over to php.net and found that but thanks anyway. As it happens I may be doing your original suggestion as I am trying to up the memory limit specifically for Drupal. Have found that there is a settings.php file where ini_set('memory_limit','16M');
    can be used. This will probably be the best method in this case after all.

  10. #10
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    lol.

    At least you will have a reference for when you don't have the header file.
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona


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
  •