Reply to Re: cache xml objects in php5

Your name:

Reply:


Posted by Kevin Wang on 09/28/05 00:20

Hi Rasmus,

Thanks a bunch for your kind help! Yes, you got exactly what I meant.

I have my own classes to hold all the xml related data, so it might be a bit
too difficult for me to convert my existing applications to use nested array
instead. I tried to use apc to store nested array though, and it works great.

I guess to only way to solve my problem is to write my own extension to
initialize my objects in my own memory (even can keep them in local memory, as
long as they are persistent across requests). You mentioned to write a MINIT
hook; could you give some more details? Is there any documentation or
available sample extensions that I can start with?

Thanks.

-- Kevin

> My php5 web application needs to parse/marshall a bunch of large xml files
into
> php5 objects at the beginning of handling each request. These xml files are
> static across all the requests and it is really time consuming to
> parse/marshall them into php5 objects.

What sort of PHP 5 objects? Do you mean simplexml objects, or do you mean
dom objects?

> I am wondering if there is any means to cache these xml objects so that each
> request will not go through the same time consuming xml parsing/building
> operation. Serialization doesn't work in my case as deserialization is also
> very expensive.
>
> I am using Apache as the web server. What I am thinking is that if php5
allows
> us to keep certain objects (and their references) around across all the
> requests in a child process instead of cleaning all the object memory every
> time after a script/request is finished.

Generally the best way to do this is to parse the data down closer to its final
usage.
Typically the final thing you need is not a simplexml or a dom object, what you
really
need is structured data and this can typically be represented with an
associative
array. Once you have it down to an array, you can use pecl/apc and its
apc_store()/
apc_fetch() functions to cache these in shared memory without the slowdown of
serialization. A decent example of this technique can be found in the little
simple_rss
function I wrote a while ago which parses all sorts of RSS feeds into a nested
array and
caches this final array in shared memory using APC.

There really is no decent way to cache an object in shared memory without
serialization.
The simpler data types can however be cached with APC. Making them persistent
is also
a problem as it completely violates PHP's request sandbox concept. If you
really feel
you need this, write yourself a PHP extension and initialize these objects in
your MINIT
hook so they only get loaded at server startup and they will be available for
the life of
that process.

Jasper Bryant-Greene wrote:
> Have you looked at memcache?
> http://www.php.net/manual/en/ref.memcache.php
>
> You install and run the memcached server (it can be on localhost for a
> single server setup, or for many servers it can be shared if the
> interconnects are fast enough). Then you can cache just about any PHP
> variable, including objects, in memory.

He did say that serialization wasn't an option and you can't use memcached
without serializing. You may not realize you are serializing, but the memcache
extension serializes internally. There was also no mention of needing to cache
across servers here.

-Rasmus (attempting to use the new Yahoo! Mail webmail for php-general)



__________________________________
Yahoo! Mail - PC Magazine Editors' Choice 2005
http://mail.yahoo.com

[Back to original 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

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