1

I am using ini_set("memory_limit","256M"); to perform some actions which are not possible without changing memory limit by PHP code. But I want to reset memory limit back to default after executing that particular task

For Example

public function myFunction(){
   ini_set("memory_limit","256M");

   //Perform heavy actions

   resetMemoryLimitToDefault(); //Reset memory Limit
}
2
  • the limit will just apply for the single script execution. you dont neet to 'reset' it Commented Aug 16, 2017 at 21:12
  • yes "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. " php.net/manual/en/function.ini-set.php Commented Aug 16, 2017 at 21:17

1 Answer 1

5

Save the value and then set it back:

public function myFunction(){
   $memory_limit0 = ini_get("memory_limit");
   ini_set("memory_limit","256M");

   //Perform heavy actions

   ini_set("memory_limit", $memory_limit0);
}

Keep in mind this change only lasts for the duration of the script, so "resetting" it might not be needed.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.