473,800 Members | 2,365 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
12 3192
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*******@attgl obal.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
2293
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
1789
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
18509
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
4692
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
1747
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
2364
by: SoulIntruder | last post by:
Hello folks. I have a beginners question. I have such script: <?php $User = $_POST; $Password = $_POST; $Database = $_POST;
5
1294
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
9697
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
9555
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
10515
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...
0
10291
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10260
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
6827
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5616
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3771
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2956
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.