PHP ob_start与opcode APC,请解释差异和实际用法? [英] PHP ob_start vs opcode APC, explain differences and real world usage?

查看:157
本文介绍了PHP ob_start与opcode APC,请解释差异和实际用法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

前提:我不是想重塑方向盘,而是想了解.

可以轻松实现输出缓存:

Output caching can be implemented easily:

//GetFromMyCache returns the page if it finds the file otherwise returns FALSE
if( ($page = GetFromMyCache($page_id)) !== FALSE )
{
   echo $page; //sending out page from cache
   exit();
}

//since we reach this point in code, it means page was not in cache
ob_start(); //let's start caching

//we process the page getting data from DB

//saving processed page in cache and flushing it out
echo CachePageAndFlush(ob_get_contents());

另一篇文章 但是随后是APC (默认情况下将包含在PHP6中).

But then comes APC (that will be included in PHP6 by default).

  1. APC是否是已安装在服务器上的模块,现有 PHP代码将无需修改而运行得更快?

  1. Is APC a module that once installed on the server, existing PHP code will run faster without modification?

APC是自动吗?

然后,为什么会有类似apc_add的功能?

Then, why are there functions like apc_add?

我们如何使用APC缓存整个页面?

How do we cache entire pages using APC?

在安装APC后,我是否还需要执行我的任何缓存?

When APC is installed, do I still need to do any caching on my part?

如果APC要节省托管服务提供商的钱,为什么他们不安装它? (我是说他们应该竞相安装它,但是我看不到这种情况.)

If APC is going to save hosting providers money, why do they not install it? (I mean they should be racing to install it, but I don't see that happening.)

对于这些托管服务提供商来说,安装APC是否有不利之处?

Does installing APC have disadvantages for these hosting providers?

推荐答案

APC是操作码缓存:

备用PHP缓存(APC)是一个免费且开放的操作码缓存,用于 PHP.其目标是为以下人员提供免费,开放且强大的框架: 缓存和优化PHP中间代码.

The Alternative PHP Cache (APC) is a free and open opcode cache for PHP. Its goal is to provide a free, open, and robust framework for caching and optimizing PHP intermediate code.

这与模板缓存(您要演示的内容)不同,并且对输出缓冲的影响很小.不是同一回事.

This is not the same as a template cache (what you are demonstrating), and it has little impact on output buffering. It is not the same thing.

Opcode缓存意味着在解释了PHP代码后缓存.这可以是任何代码片段(不一定是输出HTML的内容).例如,您可以将类和模板引擎本身保留在操作码缓存中.因为PHP解释器不需要解释"代码,所以可以大大加快您的代码的速度.再次输入您的代码,它可以简单地加载已解释"的代码缓存中的版本.

Opcode caching means cache the PHP code after it has been interpreted. This could be any code fragment (not necessarily something that outputs HTML). For example, you could stick classes and the template engine itself in an opcode cache. This would dramatically speed up your code, as the PHP interpreter doesn't need to "interpret" your code again, it can simply load the "interpreted" version from the cache.

请不要将输出缓冲与缓存混淆.缓存有很多级别,例如,您可能熟悉的最常见的两个级别.

Please do not confuse output buffering with a cache. There are many levels of caching, for example, two of the most common that you may be familiar with.

一个非常基本的版本是cookie,它存储一些设置.您只能执行计算"代码.一次(当用户登录时)进行设置,对于会话的其余部分,您可以使用缓存的" Cookie中的设置.

A very basic version of this is a cookie that stores some settings. You only execute the code that "calculates" the settings once (when a user logs in), and for the rest of the session, you use the "cached" settings from the cookie.

当需要一次生成但不经常更改的页面时,将执行此操作.例如,每日特价"页面,这是一个模板.您只需生成一次,然后投放渲染的"广告素材即可缓存中的页面.

This is done when a page that needs to be generated once, but doesn't change very often. For example a "daily specials" page, which is a template. You only generate this once, and then serve the "rendered" page from cache.

这些都不使用APC

None of these use APC

这篇关于PHP ob_start与opcode APC,请解释差异和实际用法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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