1

I'm working with infinite cycles(daemons). Which include the same script for each iteration, the scripts are included with require function. I have a problem, scripts are magnified by each iteration, How could remove the script included after each use?

  • 1
    You're probably running out of memory. Move the `require` outside of the loop, and turn the include into a function or a class so it can be used repeatedly within the loop. – sjagr Dec 05 '14 at 17:05
  • Are you currently using `require_once()` such that you are only including it 1 time? – scunliffe Dec 05 '14 at 17:06
  • A buffer overflow is possible if the number of processes increases. Each process has a limit of 32 mb. – Eduardo Wallace Dec 05 '14 at 19:08

1 Answers1

0

I do not think it is possible to remove once included/required.

I can only think of one solution and that is to encapsulate the whole script in a class (preferred if it has many steps) or a function. Once the script has been included you can use the same class/function over and over again.

Hope it helps.

AnotherGuy
  • 605
  • 11
  • 20
  • I think it's a possible solution. If a function call is performed in this way $response = set_value($param); unset($response);.... Can I release the memory used by the function? – Eduardo Wallace Dec 05 '14 at 19:19
  • That depends. If the data the function handle are processed and then stored again you can. But if you need the previous data in the next process you can't. If the first is the case, then you can just overwrite the previously used variables and maybe use `unset()` if you want to be sure. – AnotherGuy Dec 05 '14 at 21:18