我如何知道是否启用了任何 PHP 缓存?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4393626/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 12:55:44  来源:igfitidea点击:

How do I know if any PHP caching is enabled?

phpcachingapc

提问by Joker

I used to think caching was very hard to install so I've never done it... After reading about APC, it seems pretty easy to install. I always thought I would have to modify lots of PHP code inside my application to use it lol.

我曾经认为缓存很难安装,所以我从来没有这样做过......在阅读 APC 之后,它似乎很容易安装。我一直认为我必须在我的应用程序中修改大量 PHP 代码才能使用它,哈哈。

Anyways, I am wanting to install APC. I can use phpinfo() and notice it's not listed on the page, so it's not installed. Does this also show for the various other cache systems out there? I don't want to install APC if I have another caching system already installed since I'm not sure if it'll cause conflicts. Do hosts automatically install these for you?

无论如何,我想安装APC。我可以使用 phpinfo() 并注意到它没有列在页面上,所以它没有安装。这是否也适用于其他各种缓存系统?如果我已经安装了另一个缓存系统,我不想安装 APC,因为我不确定它是否会导致冲突。主机会自动为您安装这些吗?

What are the steps to check for to see if I have any sort of caching enabled?

检查我是否启用了任何类型的缓存的步骤是什么?

采纳答案by simshaun

Any installed caching extensions will be listed in your phpinfo() file; They should be listed as one of the arguments in the "Configure Command" box (e.g. -enable-apc) and should have their own sections somewhere down the page.

任何已安装的缓存扩展都将列在您的 phpinfo() 文件中;它们应该被列为“配置命令”框中的参数之一(例如 -enable-apc),并且应该在页面下方的某处有自己的部分。

Two of the most popular PHP caching modules are APC and Memcache.

两个最流行的 PHP 缓存模块是 APC 和 Memcache。

回答by Andreas Bergstr?m

To check it programmatically:

以编程方式检查它:

if(extension_loaded('apc') && ini_get('apc.enabled'))
{
    echo "APC enabled!";
}

Note: As of version 5.5 PHP now has an Opcode cache/optimizer included (though disabled by default). If you still want to run APC there is the APCu extension as @alcohol mentions in a comment. If you are using that extension you would need to replace extension_loaded('apc')with extension_loaded('apcu'). Or you could verify it from the command line:

注意:从 5.5 版开始,PHP 现在包含了 Opcode 缓存/优化器(尽管默认情况下禁用)。如果您仍想运行 APC,则@alcohol 在评论中提到了 APCu 扩展名。如果您正在使用该扩展,则需要将extension_loaded('apc')替换为extension_loaded('apc u')。或者您可以从命令行验证它:

phpX.Y -i | grep apcu

phpX.Y -i | grep apcu

Make sure though that you are using the same PHP binary that is used by your web server.

请确保您使用的 PHP 二进制文件与您的 Web 服务器使用的相同。

回答by Adam

I think typically, most caching functionality for PHP will be in the form of extensions, and these should show up in a phpinfo() call (although you'll have to recognise them).

我认为通常情况下,PHP 的大多数缓存功能将采用扩展的形式,并且这些应该显示在 phpinfo() 调用中(尽管您必须识别它们)。

You will find some that are written in PHP, and can cache page loads, esp. when that content is generated from a database or from other web requests, etc but these will generally require knowledge of said library and would require you to modify your code.

你会发现一些用 PHP 编写的,可以缓存页面加载,尤其是。当该内容是从数据库或其他 Web 请求等生成时,但这些通常需要了解所述库并需要您修改代码。

It also depends on what type of caching you're looking for, as various extensions and programs perform different tasks. While APC caches your semi-compiled/interpreted code to increase performance, something such as memcache (also recommended) aims to reduce the load on any database functionality you may be using.

它还取决于您正在寻找什么类型的缓存,因为各种扩展和程序执行不同的任务。虽然 APC 缓存您的半编译/解释代码以提高性能,但诸如 memcache(也推荐)之类的东西旨在减少您可能使用的任何数据库功能的负载。

Personally, I would look to what functionality you require, and aim to install that - unless of course it already is.

就个人而言,我会查看您需要什么功能,并打算安装它 - 当然除非它已经安装了。