使用 MMCache 或 Zend Accelerator 等 PHP 加速器是否会使 PHP 更快?

发布于 07-04 05:48 字数 233 浏览 13 评论 0原文

是否有人有使用 PHP 加速器的经验,例如 MMCacheZend 加速器? 我想知道使用其中任何一个是否可以使 PHP 与更快网络技术相媲美。 另外,使用这些是否需要权衡?

Does anybody have experience working with PHP accelerators such as MMCache or Zend Accelerator? I'd like to know if using either of these makes PHP comparable to faster web-technologies. Also, are there trade offs for using these?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(10

迷爱2024-07-11 05:48:36

目前我们使用免费的 apc,并且在我们的实时服务器上只是简单的即插即用。 为我们的网站提供了巨大的性能提升,尤其是随着项目规模的增加。 我还禁用了 apc.stat,因此它不会检查代码是否已更新,因此每当我们需要更新实时站点上的代码时,我们都会重新启动 apache。

currently we use apc, free and was just a simple plug and play on our live servers. Provided a huge performance increase for our site, especially as the project size increased. I also have the apc.stat disabled so it doesn't check if the code has been updated, so whenever we need to update the code on the live site we restart apache.

何以笙箫默2024-07-11 05:48:36

BlaM 的测试包括 WordPress 发出的所有数据库调用。 当您进行更少的数据库调用时,您会发现操作码缓存的性能提升更加显着。

BlaM's testing included all the DB calls made by WordPress. When you're making fewer DB calls, you'll see the performance gain of opcode caches be even more dramatic.

倾`听者〃2024-07-11 05:48:36

我以前使用过 Zend Accelerator(2004 年左右)。 它确实在它可以使用的代码上带来了一些显着的性能提升,但不幸的是,我使用的系统被设计为经常动态加载代码,然后评估它,Zend Accelerator 当时无法做太多事情(而且我'我猜还是不能)。

不利的一面是,我们确实看到了一些缓存问题(其中代码会发生更改,但编译版本由于某种原因与更改同步)。 我想这些问题现在可能已经解决了。

无论如何,我没有任何硬性的比较数字,当然也没有在不同的环境中编写相同的系统进行比较,但对于绝大多数系统来说,PHP 不会在性能方面杀死你。

I used Zend Accelerator a little back in the day (2004-ish). It certainly gave some significant performance wins on code it could work with, but unfortunately the system I was using was designed to quite often dynamically load code and then eval it, which Zend Accelerator couldn't do much with at the time (and I'd guess still can't).

On the down side, we certainly saw some caching issues (where the code would be changes, but the compiled version sync with the change for one reason or another). I imagine those problems have likely been ironed out by now.

Anyway, I don't have any hard comparison numbers, and certainly didn't write the same system in different environments for comparison, but for the vast majority of systems, PHP isn't going to kill you performance wise.

2024-07-11 05:48:36

我使用 APC,并且可以证明,如果您保持较高的缓存命中率,它可以显着降低应用服务器上的 CPU 和 I/O 负载。 它不仅可以让您免去编译的麻烦,还可以让您免于从磁盘读取 php 文件的麻烦。 (即字节码直接从主内存提供,因此速度非常快)它降低了渲染单个页面的速度,并增加了服务器每秒可以处理的请求数。

如果您使用 RedHat 或 CentOS,安装 APC 非常简单:

yum install php-devel httpd-devel php-pear
pecl install apc 
echo "extension=apc.so" > /etc/php.d/apc.ini
# if you're using SELinux:
chcon "system_u:object_r:textrel_shlib_t" /usr/lib/php/modules/apc.so
/etc/init.d/httpd restart

您询问了缺点。 唯一的缺点是它需要一些内存。 APC 上的默认值是 30MB,但可以调整,随着速度和响应率的提高,一点点内存的成本会物有所值。

I use APC, and can attest that it can dramatically reduce the CPU and I/O load on an app server if you maintain a high cache-hit rate. It not only saves you from having to compile, it can save you from having to read the php files from disk at all. (i.e. the bytecodes are served directly from main memory, so it's super fast) It lowers the speed to render a single page, and increases the requests per second your server can handle.

If you use RedHat or CentOS, installing APC is super simple:

yum install php-devel httpd-devel php-pear
pecl install apc 
echo "extension=apc.so" > /etc/php.d/apc.ini
# if you're using SELinux:
chcon "system_u:object_r:textrel_shlib_t" /usr/lib/php/modules/apc.so
/etc/init.d/httpd restart

You asked about downsides. The only downside is that it requires some memory. The default on APC is 30MB, but it can be adjusted, and the cost of a little bit of memory more than pays for itself with the increased speed and response rate.

坏尐絯℡2024-07-11 05:48:36

MMCache 已被弃用。 我推荐 http://pecl.php.net/package/APChttp://xcache.lighttpd.net/,两者都为您提供可变存储(如 Memcache)。

MMCache has been deprecated. I recommend either http://pecl.php.net/package/APC or http://xcache.lighttpd.net/, both of which also give you variable storage (like Memcache).

霞映澄塘2024-07-11 05:48:36

两者都很有趣,并且会提供速度提升,因为它们将源代码编译成二进制表示,然后由 PHP 引擎执行。

任何使用 PHP 运行的大型网站(例如 Facebook)都在运行某种操作码缓存系统,例如 MMCache。

问题是,根据您的系统,它们并不容易设置。

Both are interesting and will provide speed boost since they compile source code into binary representation which is then executed by the PHP engine.

Any huge web site running with PHP (Facebook for example) is running some sort of opcode cache system like MMCache.

The problem is that they are not very easy to set up depending on your system.

绿光2024-07-11 05:48:36

请注意,Zend Optimizer 和 MMCache(或类似的应用程序)是完全不同的东西。 当 Zend Optimizer 尝试优化程序操作码时,MMCache 会将脚本缓存在内存中并重用预编译的代码。

我前段时间做了一些基准测试,你可以找到 结果在我的博客中(尽管是德语)。 基本结果:

仅靠 Zend Optimizer 根本没有帮助。 实际上,我的脚本比没有优化器的脚本要慢。

当谈到缓存时:
* 最快:eAccelerator
* XCache
* APC

并且:您确实想要安装操作码缓存!

例如:
替代文本 http://blogs.interdose.com/ dominik/wp-content/uploads/2008/04/opcode_wordpress.png

这是调用 wordpress 主页 10.000 次所花费的持续时间。

编辑:顺便说一句,eAccelerator 本身包含一个优化器。

Note that Zend Optimizer and MMCache (or similar applications) are totally different things. While Zend Optimizer tries to optimize the program opcode MMCache will cache the scripts in memory and reuse the precompiled code.

I did some benchmarks some time ago and you can find the results in my blog (in German though). The basic results:

Zend Optimizer alone didn't help at all. Actually my scripts were slower than without optimizer.

When it comes to caches:
* fastest: eAccelerator
* XCache
* APC

And: You DO want to install a opcode cache!

For example:
alt text http://blogs.interdose.com/dominik/wp-content/uploads/2008/04/opcode_wordpress.png

This is the duration it took to call the wordpress homepage 10.000 times.

Edit: BTW, eAccelerator contains an optimizer itself.

后eg是否自2024-07-11 05:48:36

你检查过法兰格吗? 它将 PHP 编译为 .NET 代码。 以下是一些基准 这表明它可以显着提高性能。

Have you checked out Phalanger? It compiles PHP to .NET code. Here are some benchmarks which show that it can dramatically improve performance.

愿与i2024-07-11 05:48:36

我在生产服务器上使用 APC,它开箱即用,运行良好。 编译它并将其添加到 PHP 中,无需进行太多调整。 我偶尔检查一次只是为了查看统计信息,但由于我使用 MVC,所以所有主要文件(路由器、控制器等)很少每天发生变化,因此代码保持编译状态并运行得非常高效。

I use APC on my production servers and it works pretty well out of the box. Compile it and add it to PHP and there isn't much tweaking left to do for it. I check it every once in a while just to review stats but since I use MVC a lot all of the main files (routers, controllers, etc) rarely change on a day-to-day basis so that code stays compiled and runs pretty efficiently.

半衬遮猫2024-07-11 05:48:36

根据实际执行的 PHP 代码量以及执行所需的时间,它们可能是一个巨大的胜利。 这当然不会有什么坏处,但你看到的收获很大程度上取决于你目前的时间花在哪里。

顺便说一句,mmcache 现在已经被整合到另一个项目中,我忘记了名字,但 Google 会告诉你。

Depending on how much of your PHP code is actually executed and how long that execution takes they can be a really big win. It certainly isn't going to hurt, but the gain you see will very much depend on where your time is currently spent.

btw mmcache has been rolled into a different project now, I forget the name but Google will tell you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文