I have 2 php files:
index.php (5KB)
blob.php (50,000KB - yes, 50mb php file)
Now, index.php contains an if statement
. Like this:
if (temp>3){
blah blah
} else {
require 'blob.php';
}
Will php load all of the 50MB every time index.php is requested or only when that part of the if statement is valid?
edit - cleaned the question to be more meaningful. Take the 50mb as just an example of "very large file". I knew you guys would lose focus of the question so I tried to simplify the problem in advance and it backfired.
As the require is a normal PHP function it will only be executed in the else case, which means the file shouldn't be included in the other case. Think of echo
in the file which would then be printet even if the else path isn't executed.
But again, WHY do you have 50MB of scripts? If you are including several script may an autoloader would be a better way then including them "manually" (see here)...
Yes, of course it will be slow. 50MB in a PHP file is ludicrous, and you appear to already know this so I can't fathom why you're doing it.
If you want to bring a blob of data into scope, use the file read functions to read the raw data in a buffered fashion from a plain file into a string or something. A 50MB PHP script file is silly.
It will only load the large file when that part of the if statement is valid. According to the PHP documentation for include
(which require
is just a specialized version of):
The include() statement includes and evaluates the specified file.
So if require
is not executed then nothing will happen.
As others have said, this is going to be incredibly slow. If all of that was PHP code you might get a slight performance enhancement by caching the compiled script(s) using a tool such as eAccelerator.
Normally there wouldn't be a need for such a large script, unless you have a special reason for doing that. One suggestion is that you might want to look into modular programming.