Re: Fastest templating mechanism

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



trlists@xxxxxxxxxx wrote:

On 8 May 2005 Evert | Rooftop Solutions wrote:



What I really need is a fast lookup mechanism, to 'translate'
statements.


For example:

setOutputType('xhtml');
echo(translate('authorstart'));

the function translate opens xhtml.data, which contains:

authorstart : <span class="author">
authorend : </span>

so, the translate function looks 'authorstart' up and returns '<span class="author">'

or if you had specified 'wml' as the outputtype, the file could like like:

authorstart : <b>
authorend :  </b>

and the function would return '<b>'

This is all no problem, except that these lists can be pretty big. And I wouldn't like to load them all into the memory, or have to loop through the file every time translate is called.

So I need a very fast mechanism to overcome this problem.



I think it's called a database. The fields are outputtype, key, and text to output, with an index on outputtype + key, then you do something like this:


	select OutputText from TranslateTable where OutputType = 'wml'
	and key = 'authorstart';

I wonder how many of these you really have. If on each script invocation you will be looking up many of them (dozens or hundreds) it might be more efficient to load all the ones for the outputtype you are using into a PHP array at the start, whether that's in a hard-coded array or loaded from the database. If you're only looking up a couple then a separate database lookup for each one is probably more efficient.


Yes I thought of this, but in my case a flat file would be better. The same problem applies though:
[quote]
This is all no problem, except that these lists can be pretty big. And I
wouldn't like to load them all into the memory, or have to loop through
the file every time translate is called.
[/quote]


I don't know how much lookups there will be (can either be many or some) and I need the fastest solution there is, because the function _can_ be called loads of times. I think it will be hundreds per page, and thousands in total.

I'm already thinking of cache mechanisms, because it has to work efficiently on very high loads.

Incidentally I would say this is not a templating problem. It's simply a translation or lookup problem.



True =)

grt,
Evert

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux