同样是保留PHP文件,为么你却如此费劲呢?
<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;">PREFACE</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">PHP文件是一种以php为后缀的文件,是php脚本文件。</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">用PHP做出的动态页面与其他的编程语言相比,PHP是将程序嵌入到HTML(标准通用标记语言下的一个应用)文档中去执行,执行效率比完全生成HTML标记的CGI要高许多;</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 style="color: black;">能够</span>达到加密和优化代码运行,使代码运行更快。</span></p><img src="https://mmbiz.qpic.cn/mmbiz_png/njd1NyUU8agYhPaYm0LE1RsZIopr3ROZ422L5EsZSRtWlfhTSXicxibWUMy4ibXDzM8MgwMxXiaiba3eXQicXbEv7Aeg/640?wx_fmt=png&tp=webp&wxfrom=5&wx_lazy=1&wx_co=1" style="width: 50%; margin-bottom: 20px;"><img src="https://mmbiz.qpic.cn/mmbiz_jpg/njd1NyUU8agYhPaYm0LE1RsZIopr3ROZCibOcPraEVERMLDDNSnzLEhejaO5Kr3avaibpIRx6L83XiatFnTqvmLVg/640?wx_fmt=jpeg&tp=webp&wxfrom=5&wx_lazy=1&wx_co=1" style="width: 50%; margin-bottom: 20px;"><img src="https://mmbiz.qpic.cn/mmbiz_png/njd1NyUU8agYhPaYm0LE1RsZIopr3ROZLpfTp5Nep8jQOeyib2K8LUWyDSmxJ7r8qI5NULbPYDHPCgefAx6m2vQ/640?wx_fmt=png&tp=webp&wxfrom=5&wx_lazy=1&wx_co=1" style="width: 50%; margin-bottom: 20px;">
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">PHP文件缓存</span></p><img src="https://mmbiz.qpic.cn/mmbiz_png/njd1NyUU8agYhPaYm0LE1RsZIopr3ROZlWuYVvdKHFjsq5clZPiajiarqmQ8h3sWzVgurwS5W0EG4eBIAwYicZ4UQ/640?wx_fmt=png&tp=webp&wxfrom=5&wx_lazy=1&wx_co=1" style="width: 50%; margin-bottom: 20px;"><span style="color: black;"><strong style="color: blue;"><span style="color: black;">PHP文件缓存内容<span style="color: black;">保留</span>格式</span></strong></span><img src="https://mmbiz.qpic.cn/mmbiz_png/njd1NyUU8agYhPaYm0LE1RsZIopr3ROZDiaUrpDuWxbnYXvMPvhESf2zqVfwyGbsRticuLa1XcXP1Wvx1o3xbdkw/640?wx_fmt=png&tp=webp&wxfrom=5&wx_lazy=1&wx_co=1" style="width: 50%; margin-bottom: 20px;">
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">(1)变量 var_export 格式化成PHP正常的赋值书写格式;</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">(2)变量 serialize 序列化之后<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;">(3)变量 json_encode格式化之后<span style="color: black;">保留</span>,用的时候json_decode</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">测试结果:serialize格式的文件解析效率大于Json,Json的解析效率大于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><span style="color: black;">咱们</span>要是缓存数据<span style="color: black;">意见</span>采用序列化的形式解析数据会更快。</span></p><img src="https://mmbiz.qpic.cn/mmbiz_png/njd1NyUU8agYhPaYm0LE1RsZIopr3ROZxAkn0pzTMSrUHpQtj6IichibprEoSHDQOqjxutMD7yHWs0o22DDqIEUg/640?wx_fmt=png&tp=webp&wxfrom=5&wx_lazy=1&wx_co=1" style="width: 50%; margin-bottom: 20px;">
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;"><span style="color: black;">PHP配置文件</span></strong></p><img src="https://mmbiz.qpic.cn/mmbiz_png/njd1NyUU8agYhPaYm0LE1RsZIopr3ROZDiaUrpDuWxbnYXvMPvhESf2zqVfwyGbsRticuLa1XcXP1Wvx1o3xbdkw/640?wx_fmt=png&tp=webp&wxfrom=5&wx_lazy=1&wx_co=1" style="width: 50%; margin-bottom: 20px;">
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><img src="https://mmbiz.qpic.cn/mmbiz_png/njd1NyUU8agYhPaYm0LE1RsZIopr3ROZSclgfzW22k2O01W0pKVJ0WAckiajQtGldXdibbUorPZyc7D8wIKAZKag/640?wx_fmt=png&tp=webp&wxfrom=5&wx_lazy=1&wx_co=1" style="width: 50%; margin-bottom: 20px;"></span></p><img src="https://mmbiz.qpic.cn/mmbiz_png/njd1NyUU8agYhPaYm0LE1RsZIopr3ROZxAkn0pzTMSrUHpQtj6IichibprEoSHDQOqjxutMD7yHWs0o22DDqIEUg/640?wx_fmt=png&tp=webp&wxfrom=5&wx_lazy=1&wx_co=1" style="width: 50%; margin-bottom: 20px;"><span style="color: black;"><strong style="color: blue;"><span style="color: black;">PHP文件缓存的简单案例</span></strong></span><img src="https://mmbiz.qpic.cn/mmbiz_png/njd1NyUU8agYhPaYm0LE1RsZIopr3ROZDiaUrpDuWxbnYXvMPvhESf2zqVfwyGbsRticuLa1XcXP1Wvx1o3xbdkw/640?wx_fmt=png&tp=webp&wxfrom=5&wx_lazy=1&wx_co=1" style="width: 50%; margin-bottom: 20px;">
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><img src="https://mmbiz.qpic.cn/mmbiz_png/njd1NyUU8agYhPaYm0LE1RsZIopr3ROZsBPrYxl3QVCEMyj0Ye5MHAyO07fXBM3aic6dGQ0QibfU6cBwOOXrrR4g/640?wx_fmt=png&tp=webp&wxfrom=5&wx_lazy=1&wx_co=1" style="width: 50%; margin-bottom: 20px;"></p><img src="https://mmbiz.qpic.cn/mmbiz_png/njd1NyUU8agYhPaYm0LE1RsZIopr3ROZxAkn0pzTMSrUHpQtj6IichibprEoSHDQOqjxutMD7yHWs0o22DDqIEUg/640?wx_fmt=png&tp=webp&wxfrom=5&wx_lazy=1&wx_co=1" style="width: 50%; margin-bottom: 20px;"><img src="https://mmbiz.qpic.cn/mmbiz_jpg/njd1NyUU8agYhPaYm0LE1RsZIopr3ROZwq1D7ZKCkqXdGuoV23ibTtDj9j8W3mDHwpQXbczXibCVxTRmWaG1sZuA/640?wx_fmt=jpeg&tp=webp&wxfrom=5&wx_lazy=1&wx_co=1" style="width: 50%; margin-bottom: 20px;"><img src="https://mmbiz.qpic.cn/mmbiz_png/njd1NyUU8agYhPaYm0LE1RsZIopr3ROZr4mH23oeCW6q1Y8ClPD7zibbJKhAsGeHAlqTWAhw0rbO1futSV9Ntow/640?wx_fmt=png&tp=webp&wxfrom=5&wx_lazy=1&wx_co=1" style="width: 50%; margin-bottom: 20px;"><img src="https://mmbiz.qpic.cn/mmbiz_jpg/njd1NyUU8agYhPaYm0LE1RsZIopr3ROZwq1D7ZKCkqXdGuoV23ibTtDj9j8W3mDHwpQXbczXibCVxTRmWaG1sZuA/640?wx_fmt=jpeg&tp=webp&wxfrom=5&wx_lazy=1&wx_co=1" style="width: 50%; margin-bottom: 20px;"><img src="https://mmbiz.qpic.cn/mmbiz_png/njd1NyUU8agYhPaYm0LE1RsZIopr3ROZLpfTp5Nep8jQOeyib2K8LUWyDSmxJ7r8qI5NULbPYDHPCgefAx6m2vQ/640?wx_fmt=png&tp=webp&wxfrom=5&wx_lazy=1&wx_co=1" style="width: 50%; margin-bottom: 20px;">
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">PHP文件总结</span></p><img src="https://mmbiz.qpic.cn/mmbiz_png/njd1NyUU8agYhPaYm0LE1RsZIopr3ROZlWuYVvdKHFjsq5clZPiajiarqmQ8h3sWzVgurwS5W0EG4eBIAwYicZ4UQ/640?wx_fmt=png&tp=webp&wxfrom=5&wx_lazy=1&wx_co=1" style="width: 50%; margin-bottom: 20px;">
<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></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>将页面<span style="color: black;">所有</span>生成html静态页面,用户<span style="color: black;">拜访</span>时直接<span style="color: black;">拜访</span>的静态页面,而不会去走php服务器解析的流程。此种方式,在CMS系</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>dedecms;</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">一种比较常用的实现方式是用输出缓存:</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">Ob_start()</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">******要运行的代码*******</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">$content =ob_get_contents();</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">ob_end_clean();</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;">页面部分缓存</span></strong></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">该种方式,是将一个页面中不经常变的部分进行静态缓存,而经常变化的块不缓存,最后组装在<span style="color: black;">一块</span><span style="color: black;">表示</span>;<span style="color: black;">能够</span><span style="color: black;">运用</span>类似于ob_get_contents的方式实现,<span style="color: black;">亦</span><span style="color: black;">能够</span>利用类似ESI之类的页面片段缓存策略,使其用来做动态页面中相对静态的片段部分的缓存。</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></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>,商城中的某个商品信息,当用商品id去请求时,就会得出<span style="color: black;">包含</span>店铺信息、商品信息等数据,此时就<span style="color: black;">能够</span>将这些数据缓存到一个php文件中,文件名<span style="color: black;">包括</span>商品id来建一个<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>一个php数组之类。</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;"><span style="color: black;">查找</span>缓存</span></strong></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>;<span style="color: black;">能够</span><span style="color: black;">运用</span>类似于ob_get_contents的方式实现,<span style="color: black;">亦</span><span style="color: black;">能够</span>利用类似ESI之类的页面片段缓存策略,使其用来做动态页面中相对静态的片段部分的缓存。</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;">按内容变更进行缓存</span></strong></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>当数据库内容被修改时,即刻更新缓存文件;</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>,商品表必然比<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></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;">Apache缓存</span></strong></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">apache</span><span style="color: black;">安装完以后,是不<span style="color: black;">准许</span>被cache的。<span style="color: black;">倘若</span>外接了cache或squid服务器<span style="color: black;">需求</span>进行web加速的话,就需要在htttpd.conf里进行设置,当然前提是在安装apache的时候要激活mod_cache的模块。</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">安装apache时:./configure --enable-cache --enable-disk-cache--enable-mem-cache</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;">php APC缓存扩展</span></strong></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">Php有一个APC缓存扩展,windows下面为php_apc.dll,需要先加载这个模块,<span style="color: black;">而后</span>是在php.ini里面进行配置:</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"></span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">extension=php_apc.dll</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">apc.rfc1867 = on</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">upload_max_filesize = 100M</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">post_max_size = 100M</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">apc.max_file_size = 200M</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">upload_max_filesize = 1000M</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">post_max_size = 1000M</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">max_execution_time = 600 ; <span style="color: black;">每一个</span>PHP页面运行的最大时间值(秒),默认30秒</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">max_input_time = 600 ; <span style="color: black;">每一个</span>PHP页面接收数据所需的最大时间,默认60</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">memory_limit = 128M ; <span style="color: black;">每一个</span>PHP页面所吃掉的最大内存,默认8M。</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;">Opcode缓存</span></strong></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;"><span style="color: black;">首要</span>php代码被解析为Tokens,<span style="color: black;">而后</span>再编译为Opcode码,最后执行Opcode码,返回结果;<span style="color: black;">因此</span>,<span style="color: black;">针对</span>相同的php文件,<span style="color: black;">第1</span>次运行时<span style="color: black;">能够</span>缓存其Opcode码,下次再执行这个页面时,直接会去找到缓存下的opcode码,直接执行最后一步,而<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、Turck MM Cache、PHP Accelerator等。</span></p><img src="https://mmbiz.qpic.cn/mmbiz_png/njd1NyUU8agYhPaYm0LE1RsZIopr3ROZPDp5F5jaXkznaYzr03pMYR5w23loJdoSw2V0Sj8iblFCj7ddaFIlQDw/640?wx_fmt=png&tp=webp&wxfrom=5&wx_lazy=1&wx_co=1" style="width: 50%; margin-bottom: 20px;"><img src="https://mmbiz.qpic.cn/mmbiz_png/njd1NyUU8agYhPaYm0LE1RsZIopr3ROZPDp5F5jaXkznaYzr03pMYR5w23loJdoSw2V0Sj8iblFCj7ddaFIlQDw/640?wx_fmt=png&tp=webp&wxfrom=5&wx_lazy=1&wx_co=1" style="width: 50%; margin-bottom: 20px;"><img src="https://mmbiz.qpic.cn/mmbiz_png/njd1NyUU8agYhPaYm0LE1RsZIopr3ROZPDp5F5jaXkznaYzr03pMYR5w23loJdoSw2V0Sj8iblFCj7ddaFIlQDw/640?wx_fmt=png&tp=webp&wxfrom=5&wx_lazy=1&wx_co=1" style="width: 50%; margin-bottom: 20px;">
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">*声明:</span><span style="color: black;">本文于网络整理,版权归原作者所有,如<span style="color: black;">源自</span>信息有误或侵犯权益,请联系<span style="color: black;">咱们</span>删除或授权事宜</span></p>
你的见解真是独到,让我受益匪浅。 感谢楼主分享,祝愿外链论坛越办越好! 谷歌外链发布 http://www.fok120.com/ 论坛是一个舞台,让我们在这里尽情的释放自己。
页:
[1]