Avatar of Eduardo Fuerte
Eduardo Fuerte
Flag 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
PHPApache Web Server

Avatar of undefined
Last Comment
Dave Baldwin

8/22/2022 - Mon
Dave Baldwin

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
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?
Dave Baldwin

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.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
SOLUTION
Julian Hansen

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Eduardo Fuerte

ASKER
Good...

It's the same for the other directives:  max_execution_time  and post_max_size ?
ASKER CERTIFIED SOLUTION
Dave Baldwin

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.