PHP Object Caching performance

2019-04-02 06:06发布

Is there difference between caching PHP objects on disk rather than not? If cached, objects would only be created once for ALL the site visitors, and if not, they will be created once for every visitor. Is there a performance difference for this or would I be wasting time doing this?

Basically, when it comes down to it, the main question is:

Multiple objects in memory, PER user (each user has his own set of instantiated objects)

VS

Single objects in cached in file for all users (all users use the same objects, for example, same error handler class, same template handler class, and same database handle class)

7条回答
趁早两清
2楼-- · 2019-04-02 07:11

I have used caching SQL query results, and time-intensive calculation results and have had impressive results. right now I'm working on an application that fetches more than 200 database records (which have a a lot of SQL functions and calculation in them) from a table with more than 200,000 records, calculate results from the fetched data, for each request. I use Zend_Cache component of Zend Framework to cache the calculated results, so next time I do not need to:

  1. connect to database
  2. wait for database server to find my records, calculation my sql functions, return results
  3. fetch at least 200 (could even rich 1000) records into memory
  4. step over all these data and calculate what I want from them

I just do:

  1. call for Zend_Cache::load() method, that will do some file reading.

that will save me at least 4-5 seconds on each request (very inaccurate, I did not profile it actually. but the performance gain is quite visible)

查看更多
登录 后发表回答