|
Posted by the DtTvB on 11/25/07 04:41
FFMG wrote:
> Hi,
>
> Please help me settle a geek argument :).
>
> I believe that php caches included code whenever possible.
> So given the 2 files bellow.
>
> // file.php
> -------------------------------------
> <?php
> $value = 'Some value';
> ?>
> -------------------------------------
>
> // file.txt
> -------------------------------------
> Some value
> -------------------------------------
>
> If I try and 'use' both files to set a value.
> -------------------------------------
> EXAMPLE A
> <?php
> $value = '';
> include 'file.php';
> echo $value; // 'Some value'
> ?>
> -------------------------------------
>
> -------------------------------------
> EXAMPLE B
> <?php
> $fd = @fopen( 'file.txt', 'rb');
> $contents = '';
> while (!feof($fd)) {
> $contents .= fread($fd, 8192);
> }
> fclose($fd);
> echo $contents; // 'Some value'
> ?>
> -------------------------------------
> Ignoring the fact that Example A is simpler.
>
> Is it true that 'EXAMPLE A' will open the file, (file.php), and assign
> $value only once and then not read the file anymore, (unless it is
> changed).
> I am talking about in the life of the php.exe process, not in the life
> of the script run itself.
>
> Whereas EXAMPLE B will open, read, close the file every single time
> there is a page request.
>
> What do you think? Does include open, read, close the file in every
> request? Or will the content of both files be kept for the life of the
> process?
>
> Reagards,
>
> FFMG
>
>
No, you are wrong. Stat functions are cached, but file reading and
writing are not.
On my IRC bot application, I want to change the response text without
restarting my bot, so I used 'include'.
Seems that PHP doesn't cache the included files.
Navigation:
[Reply to this message]
|