Re: performance improvement using include(), possible to cache included code?
| From: | waldschrott | Date: | Tue, 13 Jun 2000 16:16:00 +0000 |
| Subject: | Re: performance improvement using include(), possible to cache included code? | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-21212@lists.php.net to get a copy of this message | ||
<reply-bulk> providing extracts at the end of every point, for heavy traffic core programmers :)
You are doing looping include? Sure you get performance loss - you are getting read every time. Use require at least - that'll insert the thing once.Nah, that?s not posssible. I?ve created a *benchmark app*, that resides in 4 scripts. 1 *Class file*, 1 *App file* (which includes the next two files), 1 *User-Initialization file* (the user enters some data, so it does not need to be initialized in every loop), 1 *User-Code file* (the user enters the code which should be benchmarked, it will be executed by the App file a few thousand times). I do *not* want a programmer to *modify* the Application file, because he then would have to *modifiy a complex script* and at least insert the code two time (pre-calculation how much time the script ought to need, the actual mass-executing of the code to be tested). Instead the user could use the two given User-Files. Extract: Some code from an external file should be evalulated every time, but not read every time. Problems: 1.) using *include()* that whole benchmark consumes much *more processor time*, that?s the reason why I asked for some mechanism to *cache an include() instruction*, which is in a loop - any ideas on that? Extract: include()?d, not changing, code cannot be cached (and not stored into a variable (see below), without problems 2.)
include is read+eval, basically. you?re right3)
That's a valid point. I really don't know why it isn't. Though, I think you could do it with fread(filesize()).We could *modifiy readfile()* to take an *additional flag* which indicates whether a file should be fetched as an *array* (standard to preserve compatibilty), as a whole *string* or as an *object* (to add in future :) - just kidding, I think the last one makes no sense... ) Extract: mixed readfile(string filename, flag return-type); 4.)
Err, not exactly understood what you mean. Could you give an example. Sure:<?php $string=<<<END $i+1; $a='test'; END; ?> It is simply *impossible* to store the real *unevalulated* string
VERY handy if one is able to use here docs (or another, similar syntax) which *stores everything* between the start/end marks without evalulation (very fast, evalulation of code from other files is possible). The user would then be able to create *editable parts in scripts* where other users can enter everything, *no one has to worry about escaping* \ $ or \' or \" - it?s almost impossible at the current point of development. My workaround was using readfile(filesize), but to activate color coding the file looked like this (the [? ?] tags are evalulated by the pre- calculation method... ignore it) //<?php // Code to be benchmarked:[? $i=(string)'as'; //?] Extract: Option(?) to tell <<< not to evalulate code between start/end markers I hope the problems I?ve encountered are clear now, puh... :) best regards -- o----------0-?---------O-?---?----o---?-----o o O ? . | http://www.kiffen.de | pRotec,t y0ur bRai'n |0 O ? ? ? ? 0??^(3)??'?^(3)-^(1)'^(3)?^(3)?^?^(3)~^(3)?^(3)?'^(3)???^(3)?^^(3)^(1)^ (3)???^(3)`^(3)^(o)^(3)?? ? o ¿ ? . ? | psychedelic experience | gott@kiffen.de | O ? o ? o-?--o--0-----¿-?--O-----o-----0-?----------o 0 ? ? ? . ? ?$i+1;\n$a='test'; << into $string, because HERE DOCS evalulate every line (@dave: that?s perhaps the *reason of slowlyness*) - it would be