By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,719 Members | 1,220 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,719 IT Pros & Developers. It's quick & easy.

Functions "compiled" each time?

P: n/a
Hello all.

I have an index.php file that has a lot of functions that I wrote.
Let's say for the sake of argument that there are 1000 functions of
100 lines each. The index.php file is invoked with a "state" a la
"index.php?state=L1-2L3C4-47". Different functions are called
according to what the state is, and then user actions can cause
index.php to be invoked again with a different state. For instance,
you can click an "erase this part" button, and the page will display
again with that part missing.

I don't mind if it takes even a second or two to "compile" (parse?
condense?) the functions the first time through, but a change of state
should take only 1/10 of a second or less. Apart from the compiling,
that goal is achievable, the processing isn't that complicated, but if
the php engine starts from scratch each time I pass through the file,
I will have a problem.

Or maybe, since it is a server-side process, rather than compiling the
functions once for each contact with the page, the functions are
compiled once when the first person contacts the page.

I just have no idea how it works, and I need to know so I can plan my
code accordingly.

Does somebody out there have a detailed knowledge of how this is done?

Regards,

Rick
Jul 17 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
"Rick70" wrote:
Hello all.

I have an index.php file that has a lot of functions that I wrote.
Letís say for the sake of argument that there are 1000 functions
of
100 lines each. The index.php file is invoked with a "state" a la "index.php?state=L1-2L3C4-47". Different functions are called
according to what the state is, and then user actions can cause
index.php to be invoked again with a different state. For instance, you can click an "erase this part" button, and the page will display again with that part missing.

I donít mind if it takes even a second or two to "compile"
(parse?
condense?) the functions the first time through, but a change of state should take only 1/10 of a second or less. Apart from the compiling, that goal is achievable, the processing isnít that complicated,
but if
the php engine starts from scratch each time I pass through the file, I will have a problem.

Or maybe, since it is a server-side process, rather than compiling the functions once for each contact with the page, the functions are
compiled once when the first person contacts the page.

I just have no idea how it works, and I need to know so I can plan my code accordingly.

Does somebody out there have a detailed knowledge of how this is done?
Regards,

Rick


It does start from scratch every time, and for most applications, it
seems to be just fine. If not acceptable, then look at code caching
s/w like mmcache and others.

--
http://www.dbForumz.com/ This article was posted by author's request
Articles individually checked for conformance to usenet standards
Topic URL: http://www.dbForumz.com/PHP-Function...ict151290.html
Visit Topic URL to contact author (reg. req'd). Report abuse: http://www.dbForumz.com/eform.php?p=506566
Jul 17 '05 #2

P: n/a
In article <f4**************************@posting.google.com >, Rick wrote:
Hello all.

I have an index.php file that has a lot of functions that I wrote.
Let's say for the sake of argument that there are 1000 functions of
100 lines each. The index.php file is invoked with a "state" a la
"index.php?state=L1-2L3C4-47". Different functions are called
according to what the state is, and then user actions can cause
index.php to be invoked again with a different state. i


I can't really see why you would like 1 big program.

To me it seems, that writing a program for each state results in
smaller, more maintanable programs. And if you give each program the
name of the state, it shouldn't be that hard to convert the
index.php?state=xxx to xxx.php either.

--
Tim Van Wassenhove <http://www.timvw.info>
Jul 17 '05 #3

P: n/a

"Tim Van Wassenhove" <eu**@pi.be> wrote in message
news:2r*************@uni-berlin.de...
In article <f4**************************@posting.google.com >, Rick wrote:
Hello all.

I have an index.php file that has a lot of functions that I wrote.
Let's say for the sake of argument that there are 1000 functions of
100 lines each. The index.php file is invoked with a "state" a la
"index.php?state=L1-2L3C4-47". Different functions are called
according to what the state is, and then user actions can cause
index.php to be invoked again with a different state. i


I can't really see why you would like 1 big program.

To me it seems, that writing a program for each state results in
smaller, more maintanable programs. And if you give each program the
name of the state, it shouldn't be that hard to convert the
index.php?state=xxx to xxx.php either.

--
Tim Van Wassenhove <http://www.timvw.info>


Agreed. One big program is BAD. Multiple smaller units are GOOD. If you look
at my sample application at
http://www.tonymarston.co.uk/php-mys...plication.html you will see
that I have totally separate scripts for each of the following:
- list multiple records
- insert a record
- update a record
- view a record
- delete a record
- enter search criteria

This means that each script only includes the code that IT wants, so doesn't
bother accessing code that it is not going to use. I nay have hundreds of
small units, but these are far easier to maintain that one huge unit.

This idea is not new. I learnt it 30 years ago when I was a COBOL
programmer. It is called "modular programming".

--
Tony Marston

http://www.tonymarston.net

Jul 17 '05 #4

P: n/a
Hello Tim.

It would be good to break it into several web pages.

The web page naturally breaks into sequential sections, so if there
were some sort of "include" that would include the html output of a
php program, I could do this:

<include section1.php?state=L2-3>
<include section2.php?state=L5-7>
<include section3.php?state=L11-13>
<include section4.php?state=L2C3-19>

I'm not sure I would come out ahead in execution time, since these
would have to be separate web requests in order to have separate php
contexts (like an img=... tag).

--

I come from a Tcl background. In the world of Tcl, there's a tclindex
file. Routines are searched for and loaded as they are required. Is
there something similar in Php?

Regards,

Rick
Tim Van Wassenhove <eu**@pi.be> wrote in message news:<2r*************@uni-berlin.de>...
I can't really see why you would like 1 big program.

To me it seems, that writing a program for each state results in
smaller, more maintanable programs. And if you give each program the
name of the state, it shouldn't be that hard to convert the
index.php?state=xxx to xxx.php either.

Jul 17 '05 #5

P: n/a
In article <f4**************************@posting.google.com >, Rick wrote:
Hello Tim.

It would be good to break it into several web pages.

The web page naturally breaks into sequential sections, so if there
were some sort of "include" that would include the html output of a
php program, I could do this:

<include section1.php?state=L2-3>
<include section2.php?state=L5-7>
<include section3.php?state=L11-13>
<include section4.php?state=L2C3-19>


Well for each section,

$state = 'something';
$_GET['state'] = $state;
include('section.php');

Don't see your problem?


--
Tim Van Wassenhove <http://www.timvw.info>
Jul 17 '05 #6

P: n/a
Steve, thanks for the information. Useful and to the point.
I ran across the answer to my problem in the writeup for the Pear
module Cache Lite.

<?php
require_once("Cache/Lite.php");
// (...)
$cache = new Cache_Lite();
if ($data = $Cache_Lite->get($id)) { // cache hit !
echo($data);
} else { // page has to be (re)constructed in $data
require_once("...")
require_once("...")
// (...)
$Cache_Lite->save($data);
}
?>

I was thinking in terms of C/C++ and a pre-processor. But in Php
includes are dynamic. I don't have to include everything I might
possibly need, once at the top of the file.

Regards,

Rick
Jul 17 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.