当前位置: 首页 > news >正文

PHP的apcu是什么,opcache又是什么?

1,APCu

APCu is APC stripped of opcode caching.

这是apcu的官方文档解释,简单的说APCU是从APC剥离出来的用户数据缓存功能,而去掉了apc的opcode cache。

所以后来:APCu = APC User 

APC的主要用途有两项:

  1. 将PHP代码编译之后所产生的bytecode暂存在共享内存内供重复使用,以提升应用的运行效率。(Opcode Cache)
  2. 提供用户数据缓存功能,需要显示的调用,和redis/memcache类似。(User Data Cache)

其中第一点是其主要功能,因为PHP的运行机制——每次接受一个请求时都要初始化所有的资源(将源代码编译成bytecode),执行代码,然后释放资源;但其实代码99%的情况下并不会改变,所以每次请求都编译执行十分的消耗时间。所以启用Opcache Cache后,可以在初始化资源阶段减少CPU和内存的消耗。

但是PHP从PHP 5.5开始,使用ZendOptimizerPlus作为内置的Opcode Cache实现。所以现在APCU的主要功能便不再有意义了,而且其官方也随后表示不再维护APC了。

apcu也提供了缓存常见的一些操作,如:

  • apc_add — 缓存一个变量到数据存储
  • apc_bin_dump — 获取给定文件和变量的二进制文件转储。
  • apc_bin_dumpfile — Output a binary dump of cached files and user variables to a file
  • apc_bin_load — Load a binary dump into the APC file/user cache
  • apc_bin_loadfile — Load a binary dump from a file into the APC file/user cache
  • apc_cache_info — Retrieves cached information from APC's data store
  • apc_cas — 用新值更新旧值
  • apc_clear_cache — 清除APC缓存
  • apc_compile_file — Stores a file in the bytecode cache, bypassing all filters
  • apc_dec — Decrease a stored number
  • apc_define_constants — Defines a set of constants for retrieval and mass-definition
  • apc_delete_file — Deletes files from the opcode cache
  • apc_delete — 从用户缓存中删除某个变量
  • apc_exists — 检查APC中是否存在某个或者某些key
  • apc_fetch — 从缓存中取出存储的变量
  • apc_inc — 递增一个储存的数字
  • apc_load_constants — Loads a set of constants from the cache
  • apc_sma_info — Retrieves APC's Shared Memory Allocation information
  • apc_store — Cache a variable in the data store

但apcu也有一个明显的缺点:这意味着如果您将PHP用作FastCGI进程(例如Nginx和php-fpm),则每个PHP进程都会拥有自己的缓存。在FastCGI模式下重启后将会清除缓存。

 

2, Opcache  

opcache就是APC剥离出的第一个缓存字节码的功能缓存。

OPCache is a special caching mechanism that stores precompiled versions of the PHP files. When executed, a PHP file is compiled to bytecode and once this process is done, the bytecode is executed.

OPCache是​​一种特殊的缓存机制,用于存储PHP文件的预编译版本。执行后,一个PHP文件被编译为字节码,一旦完成此过程,字节码便被执行。

自PHP 5.5起,它已捆绑在内核中,只需安装它即可使我们获得极大的速度改进,而不必像apcu那样去显式的调用它。


http://www.taodudu.cc/news/show-6117757.html

相关文章:

  • 【physx/wasm】在physx中添加自定义接口并重新编译wasm
  • excel---常用操作
  • Lora训练Windows[笔记]
  • linux基础指令讲解(ls、pwd、cd、touch、mkdir)
  • InnoDB 事务处理机制
  • 启明云端ESP32 C3 模组WT32C3通过 MQTT 连接 AWS
  • 全志H3停产,A40I/T3更胜一筹--CoM-X40I核心模块来了
  • i5 6600 HD530联想扬天S5250黑苹果
  • 全志科技A40i国产开发板——性能参数综合测试
  • 全志A40i开发板(4核ARM CortexA7)测评合集——存储介质读写测试
  • 全国产!全志A40i+Logos FPGA核心板(4核ARM Cortex-A7)硬件说明
  • 【解决电脑】开机屏幕左键无反应,右键变加载;选择文件夹未响应,卡顿40秒后恢复;新建文件夹正常,删除移动卡顿
  • 全志A40i工业核心板,100%国产4核ARM Cortex-A7,支持“双屏异显”【显示接口能力,工业HMI首选方案】
  • PPT模板大全
  • 哪里有纯免费的PPT模板下载网站?
  • 800套绝美PPT模板免费下载
  • 关于更改Python的默认工作路径
  • 学完python可以从事哪些工作?
  • Visual Studio 2019 下Python的开发环境搭建
  • python将工作表根据一列拆分成多个独立的sheet工作薄
  • python- 工作/休息/调休日怎么精准判断
  • 学习Python可以做什么工作?选哪些工作方向?
  • linux 二次封装 释放,Linux必学的60个命令(二)
  • NoSQL-Mongodb基本操作和复制集(一)
  • 认识 BASH Shell
  • 图数据库ONgDB Release v-1.0.0
  • Fish shell 入门教程
  • SHELLPUB在线查杀更新公告(文末抽奖)
  • OKOK OK
  • 极客大挑战(部分)
  • 酷派 手机 stop charging
  • kudu架构
  • 酷语言COOLang
  • 秀一波酷炫可视化大屏!
  • 极客大挑战 2021
  • Kudu概述