You are here: Re: [PHP] caching parsed XML files as DOM objects in memory « PHP « IT news, forums, messages
Re: [PHP] caching parsed XML files as DOM objects in memory

Posted by "Richard Lynch" on 10/08/05 00:19

On Wed, October 5, 2005 8:11 am, Petr Smith wrote:
> is it possible to cache parsed XML files somehow?

I think this is the wrong question...

I mean, OF COURSE, it's possible to cache them SOMEHOW.

You could toss them in your file system, or a database, insert a
machine with squid on it into the chain, or train an army of squirrels
to memorize the XML.

That last one might be impractical, as you'd need to breed super-smart
squirrels first :-)

> I'm writing template
> library based on XML. But it's not very efficient to create new
> DomDocument, load XML template, process it and show on every page hit.
> XML parsing is not very fast, and because I'm parsing XHTML with
> entities, all DTD's are parsed too. I thought about something similar
> to
> java - there I can have servlet which lives all the time the server
> lives. It can load XML and parse it only for the first time and send
> DOM
> objects to another servlets.
> I need something similar with PHP, can it be done?

I think you might want to avoid trying to do it the Java way in PHP.

PHP is share-none by architectural design, not accident, so that you
can scale up by throwing as much cheap/stock hardware at it as you can
afford instead of being forced to buy a single bigger hardware box in
the center for the shared data.

It would probably make a lot more sense to store whatever you use to
uniquely identify your XML source and the results in a database or
filesystem, and then compare time-stamps in some simple business logic
to decide to re-parse or serve from cache.

Yes, that does just foist off the shared-data to the database, or
file-system -- but those systems are specifically designed to handle
this task for a long time now with a lot of heavily tested and
optimized code. PHP and even Java can't really match that level of
testing/optimization yet simply due to relative ages.

If db and filesystem are "too slow" or you already have too many
machines running this code-base, you could write your own PHP "XML
cache server" that takes an XML id and either gets it from the db/file
cache, or parses the true original, and set up your own "server" for
this express purpose and really make it scream on speed... That's
quite a bit of work, though, and for the simplicity of the code
involved, you may be better off writing it as a C application... Or
out-sourcing that bit of code to be written with specific timing
targets for the employee to meet/beat to get their just due $$$.

--
Like Music?
http://l-i-e.com/artists.htm

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация