您是否进行了任何基准测试以证明sql调用确实存在问题? - Richard。 Hi,I''m developing a CMS and I''d like to be able cache the site "tree" ina multi-dimensional array in shared memory (far too many sql callsotherwise). When someone adds an item in the tree I need to be able toread in the array from shared memory, add the new item, then write itback to shared memory.....all in one atomic action.I''ve done plenty of research and short of using something likeeaccelerator or mmcache I''m stuck with PHP semaphores which even thendon''t appear to be thread safe, only process safe (correct me if I''mwrong) - and then I''m restricted to *nix systems.Is there any way to create a method of doing the above which will workon *nix and Windows, whether it''s multi-threaded or single-threaded?Thanks,Jim. 解决方案 Jim wrote:Hi,I''m developing a CMS and I''d like to be able cache the site "tree" ina multi-dimensional array in shared memory (far too many sql callsotherwise). When someone adds an item in the tree I need to be able toread in the array from shared memory, add the new item, then write itback to shared memory.....all in one atomic action.I''ve done plenty of research and short of using something likeeaccelerator or mmcache I''m stuck with PHP semaphores which even thendon''t appear to be thread safe, only process safe (correct me if I''mwrong) - and then I''m restricted to *nix systems.Is there any way to create a method of doing the above which will workon *nix and Windows, whether it''s multi-threaded or single-threaded?Thanks,Jim.Jim,Use a database. There are dozens around which use databases; ifimplemented properly they can be quite efficient.--==================Remove the "x" from my email addressJerry StuckleJDS Computer Training Corp. js*******@attglobal.net==================I''m developing a CMS and I''d like to be able cache the site "tree" in a multi-dimensional array in shared memory (far too many sql calls otherwise). When someone adds an item in the tree I need to be able to read in the array from shared memory, add the new item, then write it back to shared memory.....all in one atomic action. I''ve done plenty of research and short of using something like eaccelerator or mmcache I''m stuck with PHP semaphores which even then don''t appear to be thread safe, only process safe (correct me if I''m wrong) - and then I''m restricted to *nix systems. Is there any way to create a method of doing the above which will work on *nix and Windows, whether it''s multi-threaded or single-threaded?Jim,Use a database. There are dozens around which use databases; ifimplemented properly they can be quite efficient.Hi Jerry,If I could think of a way of doing it efficiently then I''d stick withdb only, but I can''t see how. For example, I have a table whichrepresents the structure of the site, so to put it simply each recordhas an id and a parent id. To build say a left hand nav I may need tocall 3 or 4 sql statements to get all the data I need which I''d liketo avoid doing if possible.Thanks,Jim."Jim" <ji***@yahoo.comwrote in messagenews:11*********************@m3g2000hsh.googlegrou ps.com...>Use a database. There are dozens around which use databases; ifimplemented properly they can be quite efficient.Hi Jerry,If I could think of a way of doing it efficiently then I''d stick withdb only, but I can''t see how. For example, I have a table whichrepresents the structure of the site, so to put it simply each recordhas an id and a parent id. To build say a left hand nav I may need tocall 3 or 4 sql statements to get all the data I need which I''d liketo avoid doing if possible.Premature optimization?Three or four sql calls is sub-millisecond (once the operating system has*cached* your database working set for you). Compare this to the tens ofmilliseconds for a TCP/IP packet exchange or, from over here in .au,hundreds of milliseconds.Have you done any benchmarking to prove the sql calls are really a problem?--Richard. 这篇关于锁定线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-20 06:01