473,401 Members | 2,125 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,401 software developers and data experts.

include/require cached and fopen is not?


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

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

Nov 24 '07 #1
12 3164
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.
js*******@attglobal.net
==================

Nov 24 '07 #2
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.
Nov 25 '07 #3

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

Nov 25 '07 #4
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.
js*******@attglobal.net
==================

Nov 25 '07 #5

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

Nov 25 '07 #6
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.
js*******@attglobal.net
==================

Nov 25 '07 #7
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/
Nov 25 '07 #8
..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
Nov 25 '07 #9
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)
Nov 26 '07 #10
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.
js*******@attglobal.net
==================

Nov 26 '07 #11

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

Nov 26 '07 #12

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

Nov 26 '07 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Andy Jacobs | last post by:
Hi All I've tried as many combinations as I can think of but I'm not getting any where. This is what I have: <? $menu = 'menus/' . $HTTP_GET_VARS . '.inc'; echo $menu; ?>
4
by: Rafal Zawadzki | last post by:
Hello, I am using php5 and I've got this piece of code: include ('http://something.somewhere/file.php?a=act') PHP instead of including file five me: PHP Fatal error: Unknown: Security...
4
by: Will | last post by:
I know I am searching using the wrong words because I can't seem to find a simple answer on this. Here's what I want to do. helper.inc <!php var $fileName2; class helper { function...
22
by: Long | last post by:
Problem: to insert the content of a file in an HTML document at a specific location. One possible way is to add a WebCharm tag like this: <%@charm:text 20 0 my_include_file.txt %> When the...
2
by: demotis | last post by:
I'm working on an internal website and have full control of the web server and php scripts. I do not, however, have the ability to change or modify internet access to allow me to get past the proxy...
111
by: Nate | last post by:
Hello, I am looking for a method to automatically declare variables in C. I'm not sure if there is a good way to do this, but I had something like this in mind... int i; for(i = 1; i < 4;...
12
by: duzhidian | last post by:
failed to open stream: No such file or directory I have the programs like this structure: a.php is locate at . b.php is located at ./lib c.php is located at ./lib/sublib a.php uses a...
10
by: SoulIntruder | last post by:
Hello folks. I have a beginners question. I have such script: <?php $User = $_POST; $Password = $_POST; $Database = $_POST;
5
by: shapper | last post by:
Hello, I am working on a web site where I have a master page. Most web site pages use this master page as base. Some scripts are used in all pages ... other just in a few pages. Should I load...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.