什么是字节码缓存,如何在 PHP 中使用?

What is a bytecode cache and how can I use one in PHP?(什么是字节码缓存,如何在 PHP 中使用?)
本文介绍了什么是字节码缓存,如何在 PHP 中使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我在网上搜索并了解到可以编译 PHP 代码以提高性能.但是怎么做呢?我可以编译面向过程和面向对象的 PHP 代码吗?

I searched on the Web and came to know that PHP code can be compiled to have performance boost. But how to do it? Can I compile both procedural and object oriented PHP code?

推荐答案

基本思路,执行PHP脚本时分两步:

The basic idea, when executing a PHP script is in two steps :

  • 首先:以纯文本形式编写的 PHP 代码被编译为操作码
  • 然后:执行那些操作码.


当你有一个 PHP 脚本时,只要不修改,操作码永远是一样的;因此,每次执行该脚本时都进行编译阶段是一种 CPU 时间的浪费.


When you have one PHP script, as long as it is not modified, the opcodes will always be the same ; so, doing the compilation phase each time that script is to be executed is kind of a waste of CPU-time.

为了防止冗余编译,您可以使用一些操作码缓存机制.

To prevent that redundant-compilation, there are some opcode caching mechanism that you can use.

一旦 PHP 脚本被编译为操作码,这些操作码将保存在 RAM 中——并在下次执行脚本时直接从内存中使用;防止编译一次又一次.

Once the PHP script has been compiled to opcodes, those will be kept in RAM -- and directly used from memory the next time the script is to be executed ; preventing the compilation from being done again and again.


使用最多的操作码缓存是APC - Alternative PHP Cache :

  • 在 PECL 上查看以下载 APC 扩展
  • 这是手册

一旦 APC 安装并正确配置,您就无需在 PHP 代码中修改任何内容:APC 将缓存操作码,仅此而已 -- 该进程对您的应用程序完全不可见.

Once APC has been installed and configured properly, there is nothing you have to modify in your PHP code : APC will cache the opcodes, and that is all -- the process is totally invisible for your application.

这篇关于什么是字节码缓存,如何在 PHP 中使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)