面试PHP主管岗位,被问到PHP的opcache是用来干吗的?
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><strong style="color: blue;">商务合作加<span style="color: black;">微X</span>:2230304070 </strong></span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><strong style="color: blue;"><span style="color: black;">学习与交流:</span></strong><a style="color: black;"><span style="color: black;"><strong style="color: blue;"><span style="color: black;">PHP技术交流<span style="color: black;">微X</span>群 </span></strong></span></a></span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;"><span style="color: black;">2023 phpStorm 正式版激活码,直接一键激活</span></strong></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;"><span style="color: black;">链接:</span></strong><span style="color: black;"><strong style="color: blue;"><span style="color: black;">https://idea.52shizhan.cn</span></strong></span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">opcache从字面意思,肯定是缓存这<span style="color: black;">一起</span>的。<span style="color: black;">然则</span>你<span style="color: black;">是不是</span><span style="color: black;">晓得</span>它的工作原理是<span style="color: black;">怎么样</span>的呢?<span style="color: black;">这儿</span>一点一点让你<span style="color: black;">认识</span>!</p>
<span style="color: black;">PHP项目中,尤其是在高并发大流量的场景中,<span style="color: black;">怎样</span><span style="color: black;">提高</span>PHP的响应时间,是一项<span style="color: black;">非常</span>重要的工作。</span><span style="color: black;">而Opcache又是优化PHP性能不可缺失的组件,尤其是应用了PHP框架的项目中,<span style="color: black;">功效</span><span style="color: black;">更加是</span><span style="color: black;">显著</span>。</span><span style="color: black;"><strong style="color: blue;"><span style="color: black;">1. 概述</span></strong></span><span style="color: black;">在理解 OPCache 功能之前,<span style="color: black;">咱们</span>有必要先理解PHP-FPM + Nginx 的工作机制,以及PHP脚本解释执行的机制。</span><span style="color: black;"><strong style="color: blue;"><span style="color: black;">1.1 PHP-FPM + Nginx 的工作机制</span></strong></span><span style="color: black;">请求从Web浏览器到Nginx,再到PHP处理完成,一共要经历如下五个<span style="color: black;">过程</span>:</span><span style="color: black;"><span style="color: black;">第1</span>步:<span style="color: black;">起步</span>服务</span>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">起步</span>PHP-FPM。PHP-FPM 支持两种通信模式:TCP socket和Unix socket;</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">PHP-FPM 会<span style="color: black;">起步</span>两种类型的进程:Master 进程 和 Worker 进程,前者负责监控端口、分配任务、管理Worker进程;后者<span style="color: black;">便是</span>PHP的cgi程序,负责解释编译执行PHP脚本。</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">起步</span>Nginx。<span style="color: black;">首要</span>会载入 ngx_http_fastcgi_module 模块,初始化FastCGI执行环境,实现FastCGI协议请求代理</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">这儿</span>要<span style="color: black;">重视</span>:fastcgi的worker进程(cgi进程),<span style="color: black;">是由于</span>PHP-FPM来管理,不是Nginx。Nginx只是代理</span></p><span style="color: black;">第二步:Request => Nginx</span>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">Nginx 接收请求,并基于location配置,<span style="color: black;">选取</span>一个合适handler</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">这儿</span><span style="color: black;">便是</span>代理PHP的 handler</span></p><span style="color: black;">第三步:Nginx => PHP-FPM</span>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">Nginx 把请求翻译成fastcgi请求</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">经过</span>TCP socket/Unix Socket 发送给PHP-FPM 的master进程</span></p><span style="color: black;">第四步:PHP-FPM Master => Worker</span>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">PHP-FPM master 进程接收到请求</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">分配Worker进程执行PHP脚本,<span style="color: black;">倘若</span><span style="color: black;">无</span>空闲的Worker,返回502错误</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">Worker(php-cgi)进程执行PHP脚本,<span style="color: black;">倘若</span>超时,返回504错误</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">处理结束,返回结果</span></p><span style="color: black;">第五步:PHP-FPM Worker => Master => Nginx</span>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">PHP-FPM Worker 进程返回处理结果,并关闭连接,等待下一个请求</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">PHP-FPM Master 进程<span style="color: black;">经过</span>Socket 返回处理结果</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">Nginx Handler<span style="color: black;">次序</span>将每一个响应buffer发送给<span style="color: black;">第1</span>个filter → 第二个 → 以此类推 → <span style="color: black;">最后</span>响应发送给客户端</span></p><span style="color: black;"><strong style="color: blue;"><span style="color: black;">1.2 PHP脚本解释执行的机制</span></strong></span><span style="color: black;"><span style="color: black;">认识</span>了PHP + Nginx 整体的处理流程后,<span style="color: black;">咱们</span>接下来看一下PHP脚本<span style="color: black;">详细</span>执行流程,<span style="color: black;">首要</span><span style="color: black;">咱们</span>看一个实例:</span><span style="color: black;"><?php</span><span style="color: black;"><span style="color: black;">if</span> (!<span style="color: black;">empty</span>($_POST)) {</span><span style="color: black;"> <span style="color: black;">echo</span> <span style="color: black;">"Response Body POST: "</span>, json_encode($_POST), <span style="color: black;">"\n"</span>;</span><span style="color: black;">}</span><span style="color: black;"><span style="color: black;">if</span> (!<span style="color: black;">empty</span>($_GET)) {</span><span style="color: black;"> <span style="color: black;">echo</span> <span style="color: black;">"Response Body GET: "</span>, json_encode($_GET), <span style="color: black;">"\n"</span>;</span><span style="color: black;">}</span><span style="color: black;"><strong style="color: blue;"><span style="color: black;"><span style="color: black;">咱们</span>分析一下执行过程:</span></strong></span><span style="color: black;">1.php初始化执行环节,<span style="color: black;">起步</span>Zend引擎,加载注册的扩展模块</span><span style="color: black;">2.初始化后读取脚本文件,Zend引擎对脚本文件进行词法分析(lex),语法分析(bison),生成语法树</span><span style="color: black;">3.Zend 引擎编译语法树,生成opcode,</span><span style="color: black;">4.Zend 引擎执行opcode,返回执行结果</span><span style="color: black;">在PHP cli模式下,每次执行PHP脚本,四个<span style="color: black;">过程</span>都会依次执行一遍;</span><span style="color: black;">在PHP-FPM模式下,<span style="color: black;">过程</span>1)在PHP-FPM<span style="color: black;">起步</span>时执行一次,后续的请求中<span style="color: black;">再也不</span>执行;<span style="color: black;">过程</span>2)~4)<span style="color: black;">每一个</span>请求都要执行一遍;</span><span style="color: black;">其实<span style="color: black;">过程</span>2)、3)生成的语法树和opcode,同一个PHP脚本每次运行的结果都是<span style="color: black;">同样</span>的,</span><span style="color: black;">在PHP-FPM模式下,每次请求都要处理一遍,是对系统资源极大的浪费,<span style="color: black;">那样</span>有<span style="color: black;">无</span>办法优化呢?</span><span style="color: black;">当然有,如:</span>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">OPCache:前身是Zend Optimizer+ ,是 Zend Server 的一个开源组件;官方出品,强力<span style="color: black;">举荐</span></span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">APC:Alternative PHP Cache 是一个开放自由的 PHP opcode 缓存组件,用于缓存、优化 PHP 中间代码;已经不更新了不<span style="color: black;">举荐</span></span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">APCu:是APC的一个分支,共享内存,缓存用户数据,<span style="color: black;">不可</span>缓存opcode,<span style="color: black;">能够</span><span style="color: black;">协同</span>Opcache <span style="color: black;">运用</span></span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">eAccelerate:<span style="color: black;">一样</span>是不更新了,不<span style="color: black;">举荐</span></span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">xCache:<span style="color: black;">再也不</span><span style="color: black;">举荐</span><span style="color: black;">运用</span>了</span></p><span style="color: black;"><strong style="color: blue;"><span style="color: black;">2. OPCache 介绍</span></strong></span><span style="color: black;">OPCache 是Zend官方出品的,开放自由的 opcode 缓存扩展,还<span style="color: black;">拥有</span>代码优化功能,省去了每次加载和解析 PHP 脚本的开销。</span><span style="color: black;">PHP 5.5.0 及后续版本中<span style="color: black;">已然</span>绑定了 OPcache 扩展。</span><span style="color: black;">缓存两类内容:</span>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">OPCode</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">Interned String,如注释、变量名等</span></p><strong style="color: blue;"><span style="color: black;">3. OPCache 原理</span></strong><span style="color: black;">OPCache缓存的机制<span style="color: black;">重点</span>是:将编译好的操作码放入共享内存,<span style="color: black;">供给</span>给其他进程访问。</span><span style="color: black;"><span style="color: black;">这儿</span>就<span style="color: black;">触及</span>到内存共享机制,<span style="color: black;">另一</span>所有内存资源操作都有锁的问题,<span style="color: black;">咱们</span>一一<span style="color: black;">诠释</span>。</span><span style="color: black;"><strong style="color: blue;"><span style="color: black;">3.1 共享内存</span></strong></span><span style="color: black;">UNIX/Linux 系统<span style="color: black;">供给</span><span style="color: black;">非常多</span>种进程间内存共享的方式:</span><span style="color: black;">1.System-V shm API: System V共享内存,</span>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">sysv shm是持久化的,除非被一个进程<span style="color: black;">知道</span>的删除,否则它始终存在于内存里,直到系统关机;</span></p><span style="color: black;">2.mmap API:</span>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">mmap映射的内存在不是持久化的,<span style="color: black;">倘若</span>进程关闭,映射随即失效,除非事先<span style="color: black;">已然</span>映射到了一个文件上</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">内存映射机制mmap是POSIX标准的系统调用,有匿名映射和文件映射两种</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">mmap的一大优点是把文件映射到进程的<span style="color: black;">位置</span>空间</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">避免了数据从用户缓冲区到内核page cache缓冲区的复制过程;</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">当然还有一个优点<span style="color: black;">便是</span>不需要频繁的read/write系统调用</span></p><span style="color: black;">3.POSIX API:System V 的共享内存是过时的, POSIX共享内存<span style="color: black;">供给</span>了<span style="color: black;">运用</span>更简单、设计更<span style="color: black;">恰当</span>的API.</span><span style="color: black;">4.Unix socket API</span><span style="color: black;">OPCache <span style="color: black;">运用</span>了前三个共享内存机制,<span style="color: black;">按照</span>配置<span style="color: black;">或</span>默认mmap 内存共享模式。</span><span style="color: black;">依据PHP字节码缓存的场景,OPCache的内存管理设计非常简单,快速读写,不释放内存,过期数据置为Wasted。</span><span style="color: black;">当Wasted内存大于设定值时,自动重启OPCache机制,清空并重新生成缓存。</span><span style="color: black;"><strong style="color: blue;"><span style="color: black;">3.2 互斥锁</span></strong></span><span style="color: black;">任何内存资源的操作,都<span style="color: black;">触及</span>到锁的机制。</span><span style="color: black;">共享内存:一个单位时间内,只<span style="color: black;">准许</span>一个进程执行写操作,<span style="color: black;">准许</span>多个进程执行读操作;</span><span style="color: black;">写操作<span style="color: black;">同期</span>,不阻止读操作,以至于很少有锁死的<span style="color: black;">状况</span>。</span><span style="color: black;">这就<span style="color: black;">诱发</span><span style="color: black;">另一</span>一个问题:新代码、大流量场景,进程排队执行缓存opcode操作;重复写入,<span style="color: black;">引起</span>资源浪费。</span><strong style="color: blue;"><span style="color: black;">4. OPCache 缓存<span style="color: black;">诠释</span></span></strong><span style="color: black;">OPCache 是官方的Opcode 缓存<span style="color: black;">处理</span><span style="color: black;">方法</span>,在PHP5.5版本之后,<span style="color: black;">已然</span>打包到PHP源码中<span style="color: black;">一块</span>发布。</span><span style="color: black;">它将PHP编译产生的字节码以及数据缓存到共享内存中, 在每次请求,从缓存中直接读取编译后的opcode,进行执行。</span><span style="color: black;"><span style="color: black;">经过</span>节省脚本的编译过程,<span style="color: black;">加强</span>PHP的运行效率。</span><span style="color: black;"><span style="color: black;">倘若</span>正在<span style="color: black;">运用</span>APC扩展,做<span style="color: black;">一样</span>的工作,<span style="color: black;">此刻</span><span style="color: black;">剧烈</span><span style="color: black;">举荐</span>OPCache来代替,尤其是PHP7中。</span><span style="color: black;"><strong style="color: blue;"><span style="color: black;">4.1 OPCode 缓存</span></strong></span><span style="color: black;">Opcache 会缓存OPCode以及如下内容:</span>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">PHP脚本<span style="color: black;">触及</span>到的函数</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">PHP脚本中定义的Class</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">PHP脚本文件路径</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">PHP脚本OPArray</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">PHP脚本<span style="color: black;">自己</span>结构/内容</span></p><span style="color: black;"><strong style="color: blue;"><span style="color: black;">4.2 Interned String 缓存</span></strong></span><span style="color: black;"><span style="color: black;">首要</span><span style="color: black;">咱们</span>需要理解,什么是 Interned String?</span><span style="color: black;">在PHP5.4的时候, 引入了Interned String机制, 用于优化PHP对字符串的存储和处理。尤其是处理大块的字符串,<span style="color: black;">例如</span>PHP doces时,Interned String <span style="color: black;">能够</span>优化内存。</span><span style="color: black;">Interned String 缓存的内容<span style="color: black;">包含</span>:变量名<span style="color: black;">叫作</span>、类名、<span style="color: black;">办法</span>名、字符串、注释等。</span><span style="color: black;">在PHP-FPM模式中,Interned String 缓存字符,仅限于Worker 进程内部。而缓存到OPCache中,<span style="color: black;">那样</span>Worker进程之间<span style="color: black;">能够</span><span style="color: black;">运用</span> Interned String 缓存的字符串,节省内存。</span><span style="color: black;"><span style="color: black;">咱们</span>需要<span style="color: black;">重视</span>一个事情,在PHP<span style="color: black;">研发</span>中,<span style="color: black;">通常</span>会有大段的注释,<span style="color: black;">亦</span>会被缓存到OPCache中。<span style="color: black;">能够</span><span style="color: black;">经过</span>php.ini的配置,关闭注释的缓存。</span><span style="color: black;"><span style="color: black;">然则</span>,像Zend Framework等框架中,会引用注释,<span style="color: black;">因此</span>,<span style="color: black;">是不是</span>关闭注释的缓存,需要区别对待。</span><span style="color: black;"><strong style="color: blue;"><span style="color: black;">5. OPCache 更新策略</span></strong></span><span style="color: black;">是缓存,都存在过期,以及更新策略等。而OPCache的更新策略非常简单,到期数据置为Wasted,达到设定值,清空缓存,重建缓存。</span><span style="color: black;"><span style="color: black;">这儿</span>需要<span style="color: black;">重视</span>:在高流量的场景下,重建缓存是一件非常耗费资源的事儿。OPCache 在创建缓存时并不会阻止其他进程读取。这会<span style="color: black;">引起</span><span style="color: black;">海量</span>进程反复新建缓存。<span style="color: black;">因此</span>,不要设置OPCache过期时间</span><span style="color: black;">每次发布新代码时,都会<span style="color: black;">显现</span>反复新建缓存的<span style="color: black;">状况</span>。<span style="color: black;">怎样</span>避免呢?</span>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">不要在高峰期发布代码,这是任何<span style="color: black;">状况</span>下都要遵守的规则</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">代码预热,<span style="color: black;">例如</span><span style="color: black;">运用</span>脚本批量调PHP <span style="color: black;">拜访</span>URL,<span style="color: black;">或</span><span style="color: black;">运用</span>OPCache 暴露的API 如opcache_compile_file() 进行编译缓存</span></p><span style="color: black;"><strong style="color: blue;"><span style="color: black;">6. OPCache 的配置</span></strong></span><span style="color: black;"><strong style="color: blue;"><span style="color: black;">6.1 内存配置</span></strong></span>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">opcache.preferred_memory_model="mmap" OPcache 首选的内存模块。<span style="color: black;">倘若</span>留空,OPcache 会<span style="color: black;">选取</span>适用的模块, <span style="color: black;">一般</span><span style="color: black;">状况</span>下,自动<span style="color: black;">选取</span>就<span style="color: black;">能够</span>满足<span style="color: black;">需要</span>。可选值<span style="color: black;">包含</span>:mmap,shm, posix 以及 win32。</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">opcache.memory_consumption=64 OPcache 的共享内存<span style="color: black;">体积</span>,以兆字节为单位,默认64M</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">opcache.interned_strings_buffer=4 用来存储临时字符串的内存<span style="color: black;">体积</span>,以兆字节为单位,默认4M</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">opcache.max_wasted_percentage=5 浪费内存的上限,以百分比计。<span style="color: black;">倘若</span>达到此上限,<span style="color: black;">那样</span> OPcache 将产生重新<span style="color: black;">起步</span>续发事件。默认5</span></p><span style="color: black;"><strong style="color: blue;"><span style="color: black;">6.2 <span style="color: black;">准许</span>缓存的文件数量以及<span style="color: black;">体积</span></span></strong></span>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">opcache.max_accelerated_files=2000 OPcache 哈希表中可存储的脚本文件数量上限。真实的取值是在质数集合 { 223, 463, 983, 1979, 3907, 7963, 16229, 32531, 65407, 130987 } 中找到的<span style="color: black;">第1</span>个大于等于设置值的质数。设置值取值范围最小值是 200,最大值在 PHP 5.5.6 之前是 100000,PHP 5.5.6 及之后是 1000000。默认值2000</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">opcache.max_file_size=0 以字节为单位的缓存的文件<span style="color: black;">体积</span>上限。设置为 0 <span style="color: black;">暗示</span>缓存<span style="color: black;">所有</span>文件。默认值0</span></p><span style="color: black;"><strong style="color: blue;"><span style="color: black;">6.3 注释<span style="color: black;">关联</span>的缓存</span></strong></span>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">opcache.load_commentsboolean <span style="color: black;">倘若</span>禁用,则即使文件中<span style="color: black;">包括</span>注释,<span style="color: black;">亦</span>不会加载这些注释内容。本选项<span style="color: black;">能够</span>和 opcache.save_comments <span style="color: black;">一块</span><span style="color: black;">运用</span>,以实现按需加载注释内容。</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">opcache.fast_shutdown boolean <span style="color: black;">倘若</span>启用,则会<span style="color: black;">运用</span>快速停止续发事件。<span style="color: black;">所说</span>快速停止续发事件<span style="color: black;">指的是</span>依赖 Zend 引擎的内存管理模块 一次释放<span style="color: black;">所有</span>请求变量的内存,而不是依次释放每一个已分配的内存块。</span></p><span style="color: black;"><strong style="color: blue;"><span style="color: black;">6.4 二级缓存的配置</span></strong></span>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">opcache.file_cache 配置二级缓存目录并启用二级缓存。启用二级缓存<span style="color: black;">能够</span>在 SHM 内存满了、服务器重启<span style="color: black;">或</span>重置 SHM 的时候<span style="color: black;">加强</span>性能。默认值为空字符串 "",<span style="color: black;">暗示</span>禁用基于文件的缓存。</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">opcache.file_cache_onlyboolean 启用或禁用在共享内存中的 opcode 缓存。</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">opcache.file_cache_consistency_checksboolean 当从文件缓存中加载脚本的时候,<span style="color: black;">是不是</span>对文件的校验和进行验证。</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">opcache.file_cache_fallbackboolean 在 Windows 平台上,当一个进程<span style="color: black;">没法</span>附加到共享内存的时候, <span style="color: black;">运用</span>基于文件的缓存,<span style="color: black;">亦</span>即:opcache.file_cache_only=1。需要<span style="color: black;">表示</span>的启用文件缓存。</span></p><img src="https://mmbiz.qpic.cn/mmbiz_gif/X36HLl2EicOfbCTTtzwpbdicOhvibmKu9O9jGSLPicT5IVjk2U8YETibumKAAa5K55Y3mdvGOvhjfbUGdEibKx8E5BJQ/640?wx_fmt=gif&wxfrom=5&wx_lazy=1&tp=webp" style="width: 50%; margin-bottom: 20px;"><strong style="color: blue;"><span style="color: black;">参考链接:http://kevhu.com/php/551</span></strong><span style="color: black;"><span style="color: black;">以上<span style="color: black;">便是</span>本篇分钟的<span style="color: black;">所有</span>内容,</span><span style="color: black;"><strong style="color: blue;"><span style="color: black;"><span style="color: black;">期盼</span>各位程序员们<span style="color: black;">奋斗</span><span style="color: black;">提高</span>个人技术。</span></strong></span><span style="color: black;">最后,<span style="color: black;">博主</span>温馨提示:<span style="color: black;">每日</span>阅读5分钟,<span style="color: black;">每日</span>学习一点点,<span style="color: black;">每日</span>进步一点点。</span></span>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><img src="https://mmbiz.qpic.cn/mmbiz_gif/X36HLl2EicOfSLeDjYdhheic53iaMxy6jzuQaBEXzfu12r8KsocY8g1D5GGfcUJ4nibr37JY3ZZBu1wjKiaNxEASXUA/640?wx_fmt=gif&wxfrom=5&wx_lazy=1&tp=webp" style="width: 50%; margin-bottom: 20px;"></p>
感谢楼主的分享!我学到了很多。 对于这个问题,我有不同的看法... 你的话深深触动了我,仿佛说出了我心里的声音。 外链发布论坛学习网络优化SEO。 我赞同你的看法,你的智慧让人佩服,谢谢分享。
页:
[1]