0

I wrote a PHP application which generates Excel file by using database data. I am using well-known library PHPExcel. Everyone who has work with this library knows that the memory management is the worst point of this library.

So, my question is is it okay to boost up memory until I write my excel and then bring it down?

Something like,

error_reporting(1);
ini_set('memory_limit', '500M');
@set_time_limit(0);

once finish

error_reporting(1);
ini_set('memory_limit', '128M');
@set_time_limit(0);
Community
  • 1
  • 1
TeaCupApp
  • 11,316
  • 18
  • 70
  • 150

3 Answers3

5

There's no need to set it back down. ini_set only affects the current request, not the whole server; it's implicitly set back to the server default once your request finishes.

  • Ohh that makes so much sense, Because I was looking for a spike in scoutapp but it didnt show me. Thanks duskwuff – TeaCupApp Sep 07 '12 at 07:11
0

It's probably the only way to get it working.

Contrary to the other responses, there might be a need to bring the memory limit down. In case of many simultaneous requests you would eat up all memory faster (although in most cases it won't be noticeable).

I mean, it's just good practice - sometimes every byte counts.

By the way, the second error_reporting and the second set_time_limit do nothing.

$reporting = error_reporting(E_ERROR);
// some code
error_reporting($reporting);

Perhaps you something like this?

Paul S.
  • 1,583
  • 1
  • 11
  • 14
  • Decreasing the memory limit will not decrease the memory consumption of your application, other than by killing off requests which try to use more memory than they're allowed. It's not a memory allocation; it's more of a memory electric fence. –  Sep 07 '12 at 15:34
0

This is okay to do, but don't set it any higher than it needs to be. You should set a limit to the number of rows/columns that PHPExcel can generate, and then test the system's memory usage at that limit.

As @duskwuff said, you don't need to run ini_set twice. It will set itself back to whatever your system configuration is.

Matthew Blancarte
  • 8,251
  • 2
  • 25
  • 34