0

I have PHP application, that runs about 2-3 minutes before it return something to browser (some database processing stuff).

I want to know, if I can change php file with it while script is running. I assume, there is a buffer in Apache/PHP.

I have situation like this:

// This is index.php

include "DatabaseController.php"; // class inside, I create instance at start
include "ImagesController.php";  // class inside, I create instance at start
include "helpers.php"; // there are just functions, no classes

$db = new Database();
$img = new Images();

// for loop doing job here (2-3 minutes)

// end

What will happen, when I replace "DatabaseController.php" file while script is running?

I tried to test it, and it looks like "job part" is still using old version of DatabaseController, when I replace.

But... what will happen, when I replace "helpers.php" file? It contains only functions, without classes that may be instantiated at the beginning of script.

How this buffering works in general?

Kamil
  • 13,363
  • 24
  • 88
  • 183
  • Nothing will happen if you change the file while its in executing... –  Aug 01 '13 at 23:18
  • You mean, that all included files are buffered too? – Kamil Aug 01 '13 at 23:19
  • 1
    If they're included already, their behavior won't change (changed to opcode). If your script starts, _then_ you change the file, and only _then_ the `include` happens, it will of course see the new file. – Wrikken Aug 01 '13 at 23:21
  • Yes, because included files are part of the main file, everything will be loaded and then executed, therefore, once the request sent, and the files being included, changes not affect them at all... –  Aug 01 '13 at 23:22
  • @Wrikken: the time is very very very small, that I can say its zero for manual changing –  Aug 01 '13 at 23:23
  • @Akem: well, yes, usually, in web context, indeed. If you have a job running somewhere that takes longer then a few (micro)seconds before it encounters an include it becomes another matter. – Wrikken Aug 01 '13 at 23:29

1 Answers1

1

Its not really being buffered. You should read up on Compilers. In summary, the code you write will first need to be compiled before it can be executed. Changes you make to the source after it has been compiled will not take effect until the next request when it will be recompiled again.

shxfee
  • 5,188
  • 6
  • 31
  • 29