How to set different PHP memory_limit value only in a file

  • basketmen
  • Student
  • Student
  • basketmen
  • Posts: 69

Post 3+ Months Ago

Hi guys,

In Cpanel WHM >> PHP Configuration Editor (php.ini) >> the memory_limit is set to 30M, so the server does not use too high of resources, 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?
Moderator Remark: Re-worded original post
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9091
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

Noticed it has been awhile and nobody has answered your post. You could do this in a single file by using the PHP ini_set function if your server configuration allows you to use this. Many web hosts will have ini_set as part of the disabled_functions configuration option though, which would prevent you from doing it this way. If you can use it though, then you would do it like this:

PHP Code: [ Select ]
ini_set('memory_limit','128M');


You could also do it on a per directory basis. For instance if you had a folder on a website that you wanted to allow php files larger access to memory, you could include a .htaccess file in that directory and put this:

Code: [ Select ]
php_value memory_limit 128M


That would up the limit from 30 MB to 128 MB for anything in that directory and under. If your server is configured in a way where you cannot change that value using .htaccess files, then you may be also able to do this by including a file called php.ini in any folder and putting the variables in there you want to change. This could in effect allow you to also up the memory limit. So you would do this by creating a php.ini file and simply putting this inside it:

Code: [ Select ]
memory_limit = 128M
  • basketmen
  • Student
  • Student
  • basketmen
  • Posts: 69

Post 3+ Months Ago

yes i know to set per directory basis

i am searching if there is any to set per file basis, the last alternative way maybe i will move the files needed to a new folder and set the directory memory_limit there
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9091
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

I am thinking the only per file method is to use the ini_set function as mentioned in my last post. I did edit the post above to include that, so its possible you overlooked it if you were reading my post as I made the change.
  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13504
  • Loc: Florida

Post 3+ Months Ago

As long as the file isn't being included, and "some.php" is in the request URI, I think you can use Apache's <Files/> wrapper.

APACHE Code: [ Select ]
<Files "some.php">
php_value memory_limit 128M
</Files>
  1. <Files "some.php">
  2. php_value memory_limit 128M
  3. </Files>
  • basketmen
  • Student
  • Student
  • basketmen
  • Posts: 69

Post 3+ Months Ago

cool, so there is this condition

where i can add that, in the bottom php.ini?

and how to wrap some files, not only a file
  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13504
  • Loc: Florida

Post 3+ Months Ago

It's an Apache configuration directive. The contexts it's available in are server config, virtual host, directory, and htaccess. Here is a little more on How <Directory>, <Location> and <Files> sections work.

Post Information

  • Total Posts in this topic: 7 posts
  • Users browsing this forum: No registered users and 123 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.