Include vs exec
| From: | Chris Chabot | Date: | Tue, 04 Jan 2000 03:46:38 +0000 |
| Subject: | Include vs exec | ||
| References: | 1 | Groups: | php.version4 |
| Request: | Send a blank email to php-version4+get-8889@lists.php.net to get a copy of this message | ||
Ive recently run into what seems to be a limitation of PhP while implimenting
a templating engine.
the 2 functionalities im trying to combine are:
filter key frazes (eg replace @title@ by 'This is a title')
allow php execution (eg allow <? echo 'a'; ?>)
these 2 specs seem to be hard to combine. If i had just the ereg_replace, i
could load the template (html file) into mem, parse the @var@'s, and echo the
result to stdout. Also if i just wanted to do php execution i would read the
(php) file into memory and call exec("$template")
but how do i do a combination of both? all i can think of is read the
template file containing both php code and html into memory, ereg_replace the
@var@'s, write the output to a temp file, and then include($file) the thing.
This however would kill performance, and thus it wouldnt be a very nice
solution for me. Also this would limit my potential expantions. I'd like to
be able to use sysv shared mem for this engine one day, and read the template
into shared memory, and load it from there on every calling of the page, this
would save me a lot of sql and/or file calls, thus cutting down stackswitches
and system time dramaticly
(eg flow would be:
if (on first read, or template update) then (read 'file/sql blob' into
sysv shmem)
load template from shmem into $template
parse @var@'s in the $template string (ereg_replace on string)
'include' (read include functionality: exec + echo) the $template string
(call strinclude($template)?).
)
i hope this is a limitation we can easely overcome, and it would definaly
make my life a lot easier!
-- Chris Chabot