473,402 Members | 2,053 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,402 software developers and data experts.

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

If I do a require_once("somefile.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_document();
$obj = new Expensive_Object();
// Other "expensive" things.
require_once,_no_really_this_time("some_library.ph p");
}

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 6892
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*****@holyflatnetshit.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.32602$po.292187@attbi_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 "compilation"

If I do a require_once("somefile.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
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 ==...
7
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...
2
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...
7
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....
4
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...
16
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...
2
by: jbanik10 | last post by:
. What errors are caught at compile time vs link time?
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
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.