Re: mysql cache query as xml

From: Date: Fri, 10 Jul 2009 19:05:54 +0000
Subject: Re: mysql cache query as xml
References: 1 2 3 4  Groups: php.general 
Request: Send a blank email to php-general+get-295160@lists.php.net to get a copy of this message
workerholic@studysite.eu wrote:
hi andrew i think you understand my problem a little, but if 100 user load this query at the same time, the two mysql server had a lot to do! so i think to cache this query as xml to the application server local make thinks faster, but, i would like to have the same performance to read this xml document as read the query from mysql server... i dont know why php is so slow to read the xml file...
Are you saving to file or caching as a query result? Also note that you can cache an array of rows (at least with APC but I suspect memcache as well) - say my_fetch(key) is you function to fetch from cache and my_store(key,data,life) is your function to store. $result = my_fetch('big_query'); if (! $result) { $sql = 'your query'; $rs = mysql_query($sql); while ($row = mysql_fetch_object($rs)) {
     $result[] = $row;
     }
my_store('big_query',$result,21600); } No xml involved and you can loop through the results. If you'd rather do it as xml, you can cache the xml as a string and then fetch it, importing it into a DOM or whatever to extract your results. $xml = my_fetch('queryResultAsXML'); if (! $xml) { generate xml and cache it } $dom = new DOMDocument('1.0','utf-8'); $dom->loadXML($xml); Not sure what you are doing, apoligize if these suggestions are useless or already considered.

« previous php.general (#295160) next »