473,811 Members | 3,152 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Compile time -vs- runtime?

Just curious and I haven't really seen anything about this anywhere.

Is there an explanation of the stages PHP goes through in compiling -vs-
parsing a PHP script? google resulted in lots of pages about how to
compile PHP itself, but couldn't find anything about the stages of
php "compilatio n"

If I do a require_once("s omefile.php"); does somefile.php get loaded and
parsed once for each web request? (Guess I'm wondering what PHP's
equivelant of perl's 'use' is)

Is there some way one could do this (psuedo code):
// This would run ONLY once during (or just after) the file is parsed.
// it would not run on each web request, but it's variables are usable
// across multiple requests. perhaps things like $_SERVER and
// $_POST/$_GET wouldn't be available (or usable)
//
compile_time: {
$conf = parse_ini_file( );
$doc = parse_xml_docum ent();
$obj = new Expensive_Objec t();
// Other "expensive" things.
require_once,_n o_really_this_t ime("some_libra ry.php");
}

Now share $conf, $doc, $obj and other variables with each web request.

The big question is the require_once() stuff.

Jamie



Jul 17 '05 #1
3 6914
With total disregard for any kind of safety measures thumb_42
@yahoo.com leapt forth and uttered:
Is there some way one could do this (psuedo code):


No.

PHP re-initialises itself on every script request. Thats just the way
it is. Although it is possible to serialise objects and store them in
sessions which would give you some measure of persistance.

--
Phil Roberts | Dork Pretending To Be Hard | http://www.flatnet.net/
Jul 17 '05 #2
Phil Roberts <ph*****@holyfl atnetshit.net> wrote:
With total disregard for any kind of safety measures thumb_42
@yahoo.com leapt forth and uttered:
Is there some way one could do this (psuedo code):


No.

PHP re-initialises itself on every script request. Thats just the way
it is. Although it is possible to serialise objects and store them in
sessions which would give you some measure of persistance.


Hmm.. is there an explanation some place about when a require_once()
actually does the require? I mean, does it load and parse on each
request too? (this is the part that I've really wondered about, I've
heard different explanations about it, some say it compiles for speed
but other places say it doesn't and I wonder how it manages to be
almost as fast as a static HTML file.

Jamie
Jul 17 '05 #3

Uzytkownik <th******@yahoo .com> napisal w wiadomosci
news:bK06c.3260 2$po.292187@att bi_s52...
Just curious and I haven't really seen anything about this anywhere.

Is there an explanation of the stages PHP goes through in compiling -vs-
parsing a PHP script? google resulted in lots of pages about how to
compile PHP itself, but couldn't find anything about the stages of
php "compilatio n"

If I do a require_once("s omefile.php"); does somefile.php get loaded and
parsed once for each web request? (Guess I'm wondering what PHP's
equivelant of perl's 'use' is)

Is there some way one could do this (psuedo code):


The way I understand the process is that the parser parses the PHP code into
tokens, checking syntax along the way, the compiler turns the tokens into a
opcode tree, then the execution unit runs the opcodes. My guess is that when
you do a require or include, PHP parses and compile the file, then insert
the opcodes into the main opcode tree. This happens for every request,
unless you have the Zend Accelerator, which saves the opcode tree in share
memory so that the initialial stages don't need to occur over and over
again.

Require()s used to happen during the parsing stage. This is back in the days
of PHP3. Now it happens at run time, like include()s.
Jul 17 '05 #4

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

Similar topics

11
2015
by: Markus Dehmann | last post by:
I have a big class that contains code like this (the code is automatically generated according to some configuration): if(str == "name1"){ do; something; name1_specific; }else if(str == "name2"){ do; something;
7
5394
by: Samee Zahur | last post by:
Hello, The other day I was rather shocked to find that I couldn't find a good use for runtime polymorphism! Let me explain this a bit further before you get shocked. Any function that I could previously write like this: void func1(Base& obj) { //... obj.virmeth(); //Call virtual method //...
2
4647
by: Glen | last post by:
I'm working on a custom assembly and I'm trying to figure out the best approach to handling known constraints within the assembly, once compiled, to alert the developer at compile time of a potential issue. For example, in the assembly I would like to add a constraint that states a particular property member of the class can not be equal to one other property. In standard coding I can throw an exception during run-time, but I would rather...
7
4502
by: Holger (David) Wagner | last post by:
Hi Group, I've searched the Web for precompilers that compile ASPX/ASCX pages just like it can be done with JSPs, but so far, I've only found approaches targetted at increasing the performance. What I'd like to do this for, however, is discovering compile-time errors during my normal build. Currently, just a typo in a Property name goes unnoticed until the page is hit the first time which is not particularly satisfying (this is like...
4
8984
by: John Smith | last post by:
Hi I'm porting some C++ code to new platforms and have some 1-byte aligned structures which need a specific size. Since datatypes can vary on different platforms (which I found out the hard way since longs are not the same size on win64 and linux x64) I would like to do a check at compile time to make sure things are correct. This will ease future work. Is it possible to do something like the following at preprocessing stage:
16
5436
by: desktop | last post by:
I have read that using templates makes types know at compile time and using inheritance the types are first decided at runtime. The use of pointers and casts also indicates that the types will first be know at runtime. But is there some strict definitions that defines runtime code and compile time code that can be used in general?
2
2062
by: jbanik10 | last post by:
. What errors are caught at compile time vs link time?
0
9730
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
10392
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
10403
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
10136
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...
1
7671
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6893
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();...
1
4341
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
3868
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3020
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.