You are here: Re: include/require cached and fopen is not? « PHP Programming Language « IT news, forums, messages
Re: include/require cached and fopen is not?

Posted by Jerry Stuckle on 11/24/07 14:34

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.
>

No, this is not correct. It will be done on every page request.

> Whereas EXAMPLE B will open, read, close the file every single time
> there is a page request.
>

Correct.

> 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
>
>


--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация