memcached vs. internal caching in PHP?

若如初见. 提交于 2021-02-08 14:39:12

问题


I'm working on some old(ish) software in PHP that maintains a $cache array to reduce the number of SQL queries. I was thinking of just putting memcached in its place and I'm wondering whether or not to get rid of the internal caching. Would there still be a worthwihle performance increase if I keep the internal caching, or would memcached suffice?


回答1:


It seems likely that memcache (which is implemented on the metal) would be faster than some php interpreted caching scheme.

However: if it's not broken, don't fix it.

If you remove the custom caching code, you might have to deal with other code that depends on the cache. I can't speak for the quality of the code you have to maintain but it seems like one of those "probably not worth it" things.

Let me put it this way: Do you trust the original developer(s) to have written code that will still work if you rip out the caching? (I probably wouldn't)

So unless the existing caching is giving you problems I would recommend against taking it out.




回答2:


According to this blog post, the PHP internal array is way faster than any other method:

Cache Type                Cache Gets/sec

Array Cache                       365000
APC Cache                          98000
File Cache                         27000
Memcached Cache (TCP/IP)           12200
MySQL Query Cache (TCP/IP)          9900
MySQL Query Cache (Unix Socket)    13500
Selecting from table (TCP/IP)       5100
Selecting from table (Unix Socket)  7400



回答3:


There's an advantage in using memcache vs local caching if:

1) you have mulitple webservers running off the same database, and have memcache set up to run across multiple nodes

2) the database does not implement query result caching or is very slow to access

Otherwise, unless the caching code is very poor, you shouldn't expect to see much performance benefit.

HTH

C.



来源:https://stackoverflow.com/questions/3037851/memcached-vs-internal-caching-in-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!