473,789 Members | 1,746 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3189
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*******@attgl obal.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*******@attgl obal.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*******@attgl obal.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

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

Similar topics

9
2292
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
1918
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 alert: Include filename is an URL in Unknown on line 0
4
1788
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 funcOne($fileName) {
22
2909
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 HTML template is processed by a WebCharm-aware web server, the content of my_include_file.txt is inserted at the tag location. This work very much like the SSI #include tag. However, you have more control
2
18508
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 server. The web server is in the local network (behind the proxy), running Windows 2003 with Apache web server, and PHP 5. I can use the include functions to include page content from my local server, and other servers local to my machine. When I try...
111
4689
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; i++){
12
1746
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 function at b.php while b.php using a function at c.php
10
2363
by: SoulIntruder | last post by:
Hello folks. I have a beginners question. I have such script: <?php $User = $_POST; $Password = $_POST; $Database = $_POST;
5
1293
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 all scripts in master page ... I think they are cached right? Or should I load the common scripts to all pages in my master page and
0
9656
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9499
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10374
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10124
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9969
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5405
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5540
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4078
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3677
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.