使用PHP进行缓存以减轻MySQL的压力 [英] Caching with PHP to take stress away from MySQL

查看:165
本文介绍了使用PHP进行缓存以减轻MySQL的压力的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为我的应用程序编写Web服务,并且想知道处理我可能收到的大量请求的最佳方法.很多数据可能全天都不会改变,但是我正在编写的特定脚本会进行3个MySQL查询,考虑到数据可能与对该脚本的最后一个请求相同,因此看起来有些多余,如果不是一样,那没什么大不了的.

I'm writing a web service for my application and want to know the best way to handle the possibly tons of requests I might get. A lot of the data probably won't change throughout the day but the particular script I'm writing makes 3 MySQL queries which seem a little excessive considering the data will probably be the same as the last request to the script, and if it's not the same then it's no big deal.

如果我将输出的XML/JSON保存到文件中,然后全天提供给请求者,然后用第二天的第一个请求覆盖,则性能会更好吗?最好的方法是什么?

Will performance be much better if I save the output XML/JSON to a file and then serve it to the requester throughout the day and then overwrite it with the first request of the following day? What's the best way of doing this?

我知道Joomla和phpBB以及其他MySQL密集型应用程序都使用缓存,以便不进行那么多的MySQL查询,所以这就是我的想法.

I know Joomla and phpBB and other MySQL intensive applications use caching so as to not make as many MySQL queries, so this is what got me thinking.

编辑-忘记了我在Windows/IIS 7.0上

EDIT - Forgot to mention I'm on Windows/IIS 7.0

推荐答案

您应该查看 memchached :通过PHP的 memcache 内存缓存

You should take a look at memchached: access it through PHP's memcache or memcached

Memcache模块为memcached,高效的缓存守护进程提供了方便的过程和面向对象的接口,该接口专门用于减少动态Web应用程序中的数据库负载.

Memcache module provides handy procedural and object oriented interface to memcached, highly effective caching daemon, which was especially designed to decrease database load in dynamic web applications.

它完全根据您的需求而设计,并且被许多高性能的Web应用程序使用.

It is designed exactly for what you need and is used by many high-performance webapplications.

Memcached的开发是为了提高LiveJournal.com的速度.LiveJournal.com是一个站点,每天通过一堆Web服务器和一堆数据库服务器为100万用户提供超过2000万次动态页面浏览. memcached的引入极大地降低了数据库负载.

Memcached was developed to enhance the speed of LiveJournal.com, a site which was already doing 20 million+ dynamic page views per day for 1 million users with a bunch of webservers and a bunch of database servers. The introduction of memcached dropped the database load enormously.

注意
PHP中有两(2)个客户端库.可以在serverfaul.com上找到有关此问题的更多讨论: memcache-vs-memcached ,这是一个比较

Note
There are two (2) client libraries in PHP. Some more discussion on this can be found on serverfaul.com: memcache-vs-memcached and here is a comparison

这篇关于使用PHP进行缓存以减轻MySQL的压力的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆