PHP对象缓存性能 [英] PHP Object Caching performance

查看:53
本文介绍了PHP对象缓存性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在磁盘上缓存PHP对象之间有区别吗?如果缓存了对象,则只会为所有站点访问者创建一次对象,否则,将为每个访问者创建一次对象.在性能上有区别吗?还是我会浪费时间这样做?

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:

PER用户在内存中有多个对象(每个用户都有自己的实例化对象集)

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)

推荐答案

在磁盘上缓存PHP对象之间有区别吗?

Is there difference between caching PHP objects on disk rather than not?

与所有性能调整一样,您应该衡量自己在做什么,而不是盲目地执行一些您不完全了解的伏都教仪式. 当您将对象保存在$_SESSION中时,PHP将捕获对象状态并从中生成文件(序列化).在下一个请求时,PHP将创建一个新对象,并以该状态重新填充该对象.此过程比仅创建对象要昂贵得多,因为PHP必须先进行磁盘I/O,然后解析序列化的数据.这必须同时发生在读取和写入上.

As with all performance tweaking, you should measure what you're doing instead of just blindly performing some voodoo rituals that you don't fully understand. When you save an object in $_SESSION, PHP will capture the objects state and generate a file from it (serialization). Upon the next request, PHP will then create a new object and re-populate it with this state. This process is much more expensive than just creating the object, since PHP will have to make disk I/O and then parse the serialized data. This has to happen both on read and write.

通常,PHP被设计为无共享架构.这有其优点和缺点,但是试图以某种方式回避它,通常不是一个好主意.

In general, PHP is designed as a shared-nothing architecture. This has its pros and its cons, but trying to somehow sidestep it, is usually not a very good idea.

这篇关于PHP对象缓存性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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