include/require cached and fopen is not?
include/require cached and fopen is not?
am 24.11.2007 15:06:52 von FFMG
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
-------------------------------------
$value = 'Some value';
?>
-------------------------------------
// file.txt
-------------------------------------
Some value
-------------------------------------
If I try and 'use' both files to set a value.
-------------------------------------
EXAMPLE A
$value = '';
include 'file.php';
echo $value; // 'Some value'
?>
-------------------------------------
-------------------------------------
EXAMPLE B
$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
--
'webmaster forum' (http://www.httppoint.com) | 'Free Blogs'
(http://www.journalhome.com/) | 'webmaster Directory'
(http://www.webhostshunter.com/)
'Recreation Vehicle insurance'
(http://www.insurance-owl.com/other/car_rec.php) | 'Free URL
redirection service' (http://urlkick.com/)
------------------------------------------------------------ ------------
FFMG's Profile: http://www.httppoint.com/member.php?userid=580
View this thread: http://www.httppoint.com/showthread.php?t=22555
Message Posted via the webmaster forum http://www.httppoint.com, (Ad revenue sharing).
Re: include/require cached and fopen is not?
am 24.11.2007 15:34:30 von Jerry Stuckle
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
> -------------------------------------
>
> $value = 'Some value';
> ?>
> -------------------------------------
>
> // file.txt
> -------------------------------------
> Some value
> -------------------------------------
>
> If I try and 'use' both files to set a value.
> -------------------------------------
> EXAMPLE A
>
> $value = '';
> include 'file.php';
> echo $value; // 'Some value'
> ?>
> -------------------------------------
>
> -------------------------------------
> EXAMPLE B
>
> $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
==================
Re: include/require cached and fopen is not?
am 25.11.2007 05:41:55 von the DtTvB
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
> -------------------------------------
>
> $value = 'Some value';
> ?>
> -------------------------------------
>
> // file.txt
> -------------------------------------
> Some value
> -------------------------------------
>
> If I try and 'use' both files to set a value.
> -------------------------------------
> EXAMPLE A
>
> $value = '';
> include 'file.php';
> echo $value; // 'Some value'
> ?>
> -------------------------------------
>
> -------------------------------------
> EXAMPLE B
>
> $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.
Re: include/require cached and fopen is not?
am 25.11.2007 06:27:50 von FFMG
Jerry Stuckle;105090 Wrote:
>
>
> 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.
>
Are you saying that the included scripts are revalidated every single
time?
That doesn't seem very efficient/logical to me.
Are you sure?
Surely some code is in memory.
FFMG
--
'webmaster forum' (http://www.httppoint.com) | 'Free Blogs'
(http://www.journalhome.com/) | 'webmaster Directory'
(http://www.webhostshunter.com/)
'Recreation Vehicle insurance'
(http://www.insurance-owl.com/other/car_rec.php) | 'Free URL
redirection service' (http://urlkick.com/)
------------------------------------------------------------ ------------
FFMG's Profile: http://www.httppoint.com/member.php?userid=580
View this thread: http://www.httppoint.com/showthread.php?t=22555
Message Posted via the webmaster forum http://www.httppoint.com, (Ad revenue sharing).
Re: include/require cached and fopen is not?
am 25.11.2007 07:55:27 von Jerry Stuckle
FFMG wrote:
> Jerry Stuckle;105090 Wrote:
>>
>> 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.
>>
>
> Are you saying that the included scripts are revalidated every single
> time?
>
> That doesn't seem very efficient/logical to me.
> Are you sure?
>
> Surely some code is in memory.
>
> FFMG
>
>
Nope. They are revalidated every time. But it's pretty fast.
Examine the source code if you want. It's available on the PHP site.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Re: include/require cached and fopen is not?
am 25.11.2007 08:35:42 von FFMG
Jerry Stuckle;105173 Wrote:
> FFMG wrote:
> > Jerry Stuckle;105090 Wrote:
> >>
> >> 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.
> >>
> >
> > Are you saying that the included scripts are revalidated every
> single
> > time?
> >
> > That doesn't seem very efficient/logical to me.
> > Are you sure?
> >
> > Surely some code is in memory.
> >
> > FFMG
> >
> >
>
> Nope. They are revalidated every time. But it's pretty fast.
>
> Examine the source code if you want. It's available on the PHP site.
>
I am not doubting you, I just find it very strange that some code has
not been optimized.
I would have thought that some code, (or even sections of code), are
only parsed once.
That is why, (in the example given), I would have thought that EXAMPLE
A would be far more efficient than EXAMPLE B.
But essentially they are the same.
FFMG
--
'webmaster forum' (http://www.httppoint.com) | 'Free Blogs'
(http://www.journalhome.com/) | 'webmaster Directory'
(http://www.webhostshunter.com/)
'Recreation Vehicle insurance'
(http://www.insurance-owl.com/other/car_rec.php) | 'Free URL
redirection service' (http://urlkick.com/)
------------------------------------------------------------ ------------
FFMG's Profile: http://www.httppoint.com/member.php?userid=580
View this thread: http://www.httppoint.com/showthread.php?t=22555
Message Posted via the webmaster forum http://www.httppoint.com, (Ad revenue sharing).
Re: include/require cached and fopen is not?
am 25.11.2007 13:55:15 von Toby A Inkster
FFMG wrote:
> I believe that php caches included code whenever possible.
You believe incorrectly. However, there are add-ons available which do
this. eAccelerator is one -- it hooks itself straight into mod_php, so you
don't need to make any adjustments to your actual PHP scripts.
--
Toby A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux 2.6.17.14-mm-desktop-9mdvsmp, up 19:43.]
It'll be in the Last Place You Look
http://tobyinkster.co.uk/blog/2007/11/21/no2id/
Re: include/require cached and fopen is not?
am 25.11.2007 13:58:19 von Jerry Stuckle
FFMG wrote:
> Jerry Stuckle;105173 Wrote:
>> FFMG wrote:
>>> Jerry Stuckle;105090 Wrote:
>>>> 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.
>>>>
>>> Are you saying that the included scripts are revalidated every
>> single
>>> time?
>>>
>>> That doesn't seem very efficient/logical to me.
>>> Are you sure?
>>>
>>> Surely some code is in memory.
>>>
>>> FFMG
>>>
>>>
>> Nope. They are revalidated every time. But it's pretty fast.
>>
>> Examine the source code if you want. It's available on the PHP site.
>>
>
> I am not doubting you, I just find it very strange that some code has
> not been optimized.
>
> I would have thought that some code, (or even sections of code), are
> only parsed once.
>
> That is why, (in the example given), I would have thought that EXAMPLE
> A would be far more efficient than EXAMPLE B.
> But essentially they are the same.
>
> FFMG
>
>
And why are you surprised? Are you having a performance problem? Do
you see anyplace where this causes a problem? Parsing is quite fast. I
have never seen a performance problem cause by the parser.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Re: include/require cached and fopen is not?
am 25.11.2007 17:21:51 von Michael Fesser
..oO(FFMG)
>Are you saying that the included scripts are revalidated every single
>time?
>
>That doesn't seem very efficient/logical to me.
>Are you sure?
>
>Surely some code is in memory.
Not by default. But there are code caches like APC available, which keep
the compiled bytecode in memory to speed up following requests.
Micha
Re: include/require cached and fopen is not?
am 26.11.2007 04:17:04 von Kailash Nadh
include() doesn't cache files. Thats why there is include_once() to
skip inclusion of a file, if it has already been included (in the
script's runtime)
Re: include/require cached and fopen is not?
am 26.11.2007 05:09:16 von Jerry Stuckle
Kailash Nadh wrote:
> include() doesn't cache files. Thats why there is include_once() to
> skip inclusion of a file, if it has already been included (in the
> script's runtime)
>
Which has absolutely nothing to do with caching...
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Re: include/require cached and fopen is not?
am 26.11.2007 05:45:49 von FFMG
Kailash Nadh;105271 Wrote:
> include() doesn't cache files. Thats why there is include_once() to
> skip inclusion of a file, if it has already been included (in the
> script's runtime)
Sorry this was not really what I was talking about.
FFMG
--
'webmaster forum' (http://www.httppoint.com) | 'Free Blogs'
(http://www.journalhome.com/) | 'webmaster Directory'
(http://www.webhostshunter.com/)
'Recreation Vehicle insurance'
(http://www.insurance-owl.com/other/car_rec.php) | 'Free URL
redirection service' (http://urlkick.com/)
------------------------------------------------------------ ------------
FFMG's Profile: http://www.httppoint.com/member.php?userid=580
View this thread: http://www.httppoint.com/showthread.php?t=22555
Message Posted via the webmaster forum http://www.httppoint.com, (Ad revenue sharing).
Re: include/require cached and fopen is not?
am 26.11.2007 06:21:47 von FFMG
Jerry Stuckle;105188 Wrote:
>
> And why are you surprised? Are you having a performance problem? Do
> you see anyplace where this causes a problem? Parsing is quite fast.
> I
> have never seen a performance problem cause by the parser.
>
(Bearing in mind that I have only just started looking at the php
source code)
I am surprised because I thought that once the code was parsed it is
executed, and therefore that the code was only parsed once.
I am not having any issues with the parser or anything, I am just
trying to understand the way it works.
I simply thought that include(...) was faster than the second example I
gave.
But include(...) does pretty much the same work.
FFMG
--
'webmaster forum' (http://www.httppoint.com) | 'Free Blogs'
(http://www.journalhome.com/) | 'webmaster Directory'
(http://www.webhostshunter.com/)
'Recreation Vehicle insurance'
(http://www.insurance-owl.com/other/car_rec.php) | 'Free URL
redirection service' (http://urlkick.com/)
------------------------------------------------------------ ------------
FFMG's Profile: http://www.httppoint.com/member.php?userid=580
View this thread: http://www.httppoint.com/showthread.php?t=22555
Message Posted via the webmaster forum http://www.httppoint.com, (Ad revenue sharing).