Link to home
Start Free TrialLog in
Avatar of Eduardo Fuerte
Eduardo FuerteFlag for Brazil

asked on

What is the better way of increase memory limit within PHP code?

Hi Experts!

I recently increased the directive  memory_limit in PHP.INI to permit a 267M file download, in test server.

When asking to the infrastructure support people to make the same in production server the suggestion was to increase memory limit just when it's necessary, in PHP code, and then restore to the anterior limit.

What is the better way in doing that ? Better, by using Codeigniter?

And then how to obtain by code the current memory_limit before to increase it and to restore it after?

Thanks in advance
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

You can use 'ini_set' with 'memory_limit' at the top of your script.  
http://php.net/manual/en/function.ini-set.php
http://php.net/manual/en/ini.core.php#ini.memory-limit
Avatar of Eduardo Fuerte

ASKER

I guess that way

ini_set( 'memory_limit', '1024M' );

And how to obtain the memory_limit directive before the operation, to restore it then?
Is it possible programatcically?
You don't have to restore it.  When you use 'ini_set', it is only valid for that page.  Just put the 'ini_set' command at the top of the page.
SOLUTION
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Good...

It's the same for the other directives:  max_execution_time  and post_max_size ?
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial