PHP Caching - Is it faster to save in database or create a file?

后端 未结 4 838
情深已故
情深已故 2021-02-06 01:16

I am currently caching dynamically generated PHP pages by saving them to a database with an expiry time field. If the page is requested again, the program checks for a unexpire

4条回答
  •  温柔的废话
    2021-02-06 01:20

    If it is faster and less server taxing to read/write from a file instead of a database, I'll switch to that. Does anyone know which is faster / best practice?

    The fastest is to use static files, because you can then issue the cache without even starting PHP (using RewriteRules). It won't scale properly if you've multiple front ends, however.

    The next best thing is to store it in memory, using Memcache for instance.

    The least preferable is to use SQL. If you stick with it, at least do your hard-drive a favor by using the Memory storage engine or equivalent (e.g. an unlogged table that lives in a tablespace stored on a RAM disk, if you're using PostgreSQL).

提交回复
热议问题