Board logo

标题: Discuz!X2.5+OPcache+伪静态 [打印本页]

作者: admin    时间: 2020-6-24 16:28     标题: Discuz!X2.5+OPcache+伪静态

笺注:这是在 LNMP一键安装包(lamp_CentOS6.9) 的基础上进行。 [root@localhost ~]# php -v PHP 7.0.7 (cli) (built: Jun 25 2020 01:53:47) ( NTS ) Copyright (c) 1997-2016 The PHP Group Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies 图片1.png 备注:PHP7系列都不再支持Zend Guard Loader ###### OPcache是Zend开发的闭源但可以免费使用的PHP优化加速缓存组件。 安装OPcache: [root@localhost ~]# cd lnmp1.3-full [root@localhost lnmp1.3-full]# ./addons.sh 图片2.png 安装或取消安装: 图片3.png OPcache安装成功: 图片4.png 服务器本地测试: [root@localhost ~]# php -v PHP 7.0.7 (cli) (built: Jun 25 2020 01:53:47) ( NTS ) Copyright (c) 1997-2016 The PHP Group Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies 在PHP测试页中,也可以看到OPcache出现了: 图片5.png PHP配置文件中,关于OPcache的配置:(此时OPcache的缓存功能已启用) [root@localhost ~]# vi /usr/local/php/etc/php.ini ;opcache [Zend Opcache] zend_extension="opcache.so" opcache.memory_consumption=128 opcache.interned_strings_buffer=8 opcache.max_accelerated_files=4000 opcache.revalidate_freq=60 opcache.fast_shutdown=1 opcache.enable_cli=1 备注: opcache.memory_consumption=128 ##为OPcache分配的共享内存,单位为MB;假如服务器的空闲内存比较多,这里的值可以调大一些。 opcache.max_accelerated_files=4000 ##缓存文件的最大数量,这里的值可以调大一些。 网站文件内容更新后,并没有出现延迟; 测试OPcache的缓存功能: [root@localhost ~]# ab -bash: ab: command not found [root@localhost ~]# yum -y install httpd-tools 在没有DNS服务器解析域名的情况下,可以在文件/etc/hosts里绑定: [root@localhost ~]# tail -1 /etc/hosts 192.168.168.130 www.zhuohua.store [root@localhost ~]# ab -n 1000 -c 100 http://www.zhuohua.store/forum.php This is ApacheBench, Version 2.3 <$Revision: 655654 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking www.zhuohua.store (be patient) Completed 100 requests Completed 200 requests Completed 300 requests Completed 400 requests Completed 500 requests Completed 600 requests Completed 700 requests Completed 800 requests Completed 900 requests Completed 1000 requests Finished 1000 requests Server Software: Apache Server Hostname: www.zhuohua.store Server Port: 80 Document Path: /forum.php Document Length: 12814 bytes Concurrency Level: 100 Time taken for tests: 7.629 seconds Complete requests: 1000 Failed requests: 977 (Connect: 0, Receive: 0, Length: 977, Exceptions: 0) Write errors: 0 Total transferred: 13637742 bytes HTML transferred: 12825836 bytes Requests per second: 131.08 [#/sec] (mean) Time per request: 762.920 [ms] (mean) Time per request: 7.629 [ms] (mean, across all concurrent requests) Transfer rate: 1745.68 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 2 7.0 0 35 Processing: 41 732 178.9 737 1487 Waiting: 11 728 178.0 727 1419 Total: 52 734 174.8 737 1487 Percentage of the requests served within a certain time (ms) 50% 737 66% 804 75% 828 80% 845 90% 883 95% 935 98% 1219 99% 1294 100% 1487 (longest request) 笺注:可以看到OPcache的缓存功能启用后,每秒最大处理请求次数为131.08次,每个请求响应时间是7.629毫秒。 在PHP配置文件中关闭OPcache的缓存功能: [root@localhost ~]# vi /usr/local/php/etc/php.ini 加上: opcache.enable=0 图片6.png 图片7.png 再次测试: [root@localhost ~]# ab -n 1000 -c 100 http://www.zhuohua.store/forum.php This is ApacheBench, Version 2.3 <$Revision: 655654 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking www.zhuohua.store (be patient) Completed 100 requests Completed 200 requests Completed 300 requests Completed 400 requests Completed 500 requests Completed 600 requests Completed 700 requests Completed 800 requests Completed 900 requests Completed 1000 requests Finished 1000 requests Server Software: Apache Server Hostname: www.zhuohua.store Server Port: 80 Document Path: /forum.php Document Length: 12735 bytes Concurrency Level: 100 Time taken for tests: 22.810 seconds Complete requests: 1000 Failed requests: 0 Write errors: 0 Total transferred: 13547060 bytes HTML transferred: 12735000 bytes Requests per second: 43.84 [#/sec] (mean) Time per request: 2280.993 [ms] (mean) Time per request: 22.810 [ms] (mean, across all concurrent requests) Transfer rate: 579.99 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 1 2.9 0 10 Processing: 41 2247 661.2 2240 4443 Waiting: 22 2149 624.0 2107 4262 Total: 41 2248 659.4 2240 4443 Percentage of the requests served within a certain time (ms) 50% 2240 66% 2429 75% 2647 80% 2776 90% 3065 95% 3229 98% 3500 99% 3635 100% 4443 (longest request) 笺注:可以看到OPcache的缓存功能没有启用时,每秒最大处理请求次数为43.845次,每个请求响应时间是22.810毫秒。 在PHP配置文件中再次启用OPcache的缓存功能: [root@localhost ~]# vi /usr/local/php/etc/php.ini 修改: opcache.enable=1 图片8.png 图片9.png 再次测试: [root@localhost ~]# ab -n 1000 -c 100 http://www.zhuohua.store/forum.php This is ApacheBench, Version 2.3 <$Revision: 655654 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking www.zhuohua.store (be patient) Completed 100 requests Completed 200 requests Completed 300 requests Completed 400 requests Completed 500 requests Completed 600 requests Completed 700 requests Completed 800 requests Completed 900 requests Completed 1000 requests Finished 1000 requests Server Software: Apache Server Hostname: www.zhuohua.store Server Port: 80 Document Path: /forum.php Document Length: 12736 bytes Concurrency Level: 100 Time taken for tests: 7.414 seconds Complete requests: 1000 Failed requests: 994 (Connect: 0, Receive: 0, Length: 994, Exceptions: 0) Write errors: 0 Total transferred: 13560824 bytes HTML transferred: 12747741 bytes Requests per second: 134.89 [#/sec] (mean) Time per request: 741.366 [ms] (mean) Time per request: 7.414 [ms] (mean, across all concurrent requests) Transfer rate: 1786.30 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 1 2.2 0 8 Processing: 53 718 177.1 692 1324 Waiting: 51 706 170.9 685 1324 Total: 60 718 175.6 692 1324 Percentage of the requests served within a certain time (ms) 50% 692 66% 765 75% 799 80% 827 90% 917 95% 970 98% 1100 99% 1233 100% 1324 (longest request) 笺注:可以看到OPcache的缓存功能再次启用后,每秒最大处理请求次数为134.89次,每个请求响应时间是7.414毫秒。 ############# ############# Discuz!是采用PHP语言开发的,动态地址不利于蜘蛛抓取,开启伪静态有利于SEO优化。 其实Discuz!不开启伪静态,也是可以进行蜘蛛抓取的。 Discuz!X2.5开启伪静态: 管理中心》全局》SEO设置》URL静态化: 图片10.png 图片11.png 注释:全选。 图片12.png 提交后,点击右上角的 查看当前的Rewrite规则 图片13.png 复制这一段代码:(站点Discuz!使用的是Apache基于域名的虚拟主机,所以这里选择Apache Web Server(虚拟主机用户) 图片14.png 笺注:也有Nginx的Rewrite规则: 图片15.png 在Discuz!的站点目录下,创建伪静态规则文件:( .htaccess ) [root@localhost zhuohua.store]# pwd /www/zhuohua.store [root@localhost zhuohua.store]# vi .htaccess # 将 RewriteEngine 模式打开 RewriteEngine On # 修改以下语句中的 /discuz 为您的论坛目录地址,如果程序放在根目录中,请将 /discuz 修改为 / #RewriteBase /discuz RewriteBase / # Rewrite 系统规则请勿修改 RewriteCond %{QUERY_STRING} ^(.*)$ RewriteRule ^topic-(.+)\.html$ portal.php?mod=topic&topic=$1&%1 RewriteCond %{QUERY_STRING} ^(.*)$ RewriteRule ^article-([0-9]+)-([0-9]+)\.html$ portal.php?mod=view&aid=$1&page=$2&%1 RewriteCond %{QUERY_STRING} ^(.*)$ RewriteRule ^forum-(\w+)-([0-9]+)\.html$ forum.php?mod=forumdisplay&fid=$1&page=$2&%1 RewriteCond %{QUERY_STRING} ^(.*)$ RewriteRule ^thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ forum.php?mod=viewthread&tid=$1&extra=page\%3D$3&page=$2&%1 RewriteCond %{QUERY_STRING} ^(.*)$ RewriteRule ^group-([0-9]+)-([0-9]+)\.html$ forum.php?mod=group&fid=$1&page=$2&%1 RewriteCond %{QUERY_STRING} ^(.*)$ RewriteRule ^space-(username|uid)-(.+)\.html$ home.php?mod=space&$1=$2&%1 RewriteCond %{QUERY_STRING} ^(.*)$ RewriteRule ^blog-([0-9]+)-([0-9]+)\.html$ home.php?mod=space&uid=$1&do=blog&id=$2&%1 RewriteCond %{QUERY_STRING} ^(.*)$ RewriteRule ^archiver/(fid|tid)-([0-9]+)\.html$ archiver/index.php?action=$1&value=$2&%1 RewriteCond %{QUERY_STRING} ^(.*)$ RewriteRule ^([a-z]+[a-z0-9_]*)-([a-z0-9_\-]+)\.html$ plugin.php?id=$1:$2&%1 [root@localhost zhuohua.store]# ll .htaccess -rw-r--r-- 1 root root 1320 2月 26 19:49 .htaccess 保存后,重启一下Apache: [root@localhost ~]# service httpd restart restart apache... done 测试: 伪静态开启后,也不是说所有URL的表现形式都显示为静态页面: 图片16.png 图片17.png 板块、文章的URL的表现形式都显示为静态页面: 图片18.png 图片19.png 相关文章: Discuz!X3.3+OPcache+伪静态 Discuz!7.2+Zend OPcache

图片附件: 图片1.png (2021-2-27 10:17, 34.76 KB) / 下载次数 116
http://blog.zhuohua.store/attachment.php?aid=15632&k=e5edd3487e8140d465760c7120cffa40&t=1714594365&sid=u0ZNWi



图片附件: 图片2.png (2021-2-27 10:18, 152.54 KB) / 下载次数 133
http://blog.zhuohua.store/attachment.php?aid=15633&k=51616dddabe3661ec6e15593fd6f709a&t=1714594365&sid=u0ZNWi



图片附件: 图片3.png (2021-2-27 10:18, 86.22 KB) / 下载次数 117
http://blog.zhuohua.store/attachment.php?aid=15634&k=d04b58eae31815ec9ecad679ab462326&t=1714594365&sid=u0ZNWi



图片附件: 图片4.png (2021-2-27 10:19, 53.41 KB) / 下载次数 128
http://blog.zhuohua.store/attachment.php?aid=15635&k=34a0f5ead14437d6bcfa309bfe79501a&t=1714594365&sid=u0ZNWi



图片附件: 图片5.png (2021-2-27 10:19, 51.92 KB) / 下载次数 137
http://blog.zhuohua.store/attachment.php?aid=15636&k=5056d4418d806a405c7e8c37ee9a2288&t=1714594365&sid=u0ZNWi



图片附件: 图片6.png (2021-2-27 10:22, 69.46 KB) / 下载次数 116
http://blog.zhuohua.store/attachment.php?aid=15637&k=ba7bd0542fdfd4e4c511c1529af7da34&t=1714594365&sid=u0ZNWi



图片附件: 图片7.png (2021-2-27 10:22, 85.69 KB) / 下载次数 118
http://blog.zhuohua.store/attachment.php?aid=15638&k=3ff7aad220370bff8c6fa788f8cf14f8&t=1714594365&sid=u0ZNWi



图片附件: 图片8.png (2021-2-27 10:23, 68.95 KB) / 下载次数 109
http://blog.zhuohua.store/attachment.php?aid=15639&k=16766757120828eea5ed47de90cbb1cf&t=1714594365&sid=u0ZNWi



图片附件: 图片9.png (2021-2-27 10:24, 85.69 KB) / 下载次数 107
http://blog.zhuohua.store/attachment.php?aid=15640&k=8f85da09844eb82fb06f1a74fc2966d3&t=1714594365&sid=u0ZNWi



图片附件: 图片10.png (2021-2-27 10:25, 116.36 KB) / 下载次数 115
http://blog.zhuohua.store/attachment.php?aid=15641&k=95183f8e68b75a7b6c929c577bab0686&t=1714594365&sid=u0ZNWi



图片附件: 图片11.png (2021-2-27 10:26, 44.87 KB) / 下载次数 110
http://blog.zhuohua.store/attachment.php?aid=15642&k=b7d36d0cce63f9b87652992d20449ef7&t=1714594365&sid=u0ZNWi



图片附件: 图片12.png (2021-2-27 10:26, 8.87 KB) / 下载次数 117
http://blog.zhuohua.store/attachment.php?aid=15643&k=b6a01b4875edb287c4176f85730a8a55&t=1714594365&sid=u0ZNWi



图片附件: 图片13.png (2021-2-27 10:26, 3.71 KB) / 下载次数 116
http://blog.zhuohua.store/attachment.php?aid=15644&k=b757945ebcbb1403b8308017733f777b&t=1714594365&sid=u0ZNWi



图片附件: 图片14.png (2021-2-27 10:27, 177.79 KB) / 下载次数 122
http://blog.zhuohua.store/attachment.php?aid=15645&k=df8141e7102a459d394bcacc4b0f1066&t=1714594365&sid=u0ZNWi



图片附件: 图片15.png (2021-2-27 10:27, 98.52 KB) / 下载次数 116
http://blog.zhuohua.store/attachment.php?aid=15646&k=968993b9facc1949e5793cae9bd72ded&t=1714594365&sid=u0ZNWi



图片附件: 图片16.png (2021-2-27 10:28, 114.75 KB) / 下载次数 105
http://blog.zhuohua.store/attachment.php?aid=15647&k=0edd3a2d9811e29fe0a8f09921ea5ce7&t=1714594365&sid=u0ZNWi



图片附件: 图片17.png (2021-2-27 10:29, 80.57 KB) / 下载次数 108
http://blog.zhuohua.store/attachment.php?aid=15648&k=5430dab6a99989baead11152b6e6d086&t=1714594365&sid=u0ZNWi



图片附件: 图片18.png (2021-2-27 10:29, 86.13 KB) / 下载次数 115
http://blog.zhuohua.store/attachment.php?aid=15649&k=2902bcaada87fd8331dcfb9e8a5cb749&t=1714594365&sid=u0ZNWi



图片附件: 图片19.png (2021-2-27 10:29, 88.24 KB) / 下载次数 122
http://blog.zhuohua.store/attachment.php?aid=15650&k=e7e8b90306b92fff85e86a6da5f1093e&t=1714594365&sid=u0ZNWi






欢迎光临 blog.zhuohua.store (http://blog.zhuohua.store/) Powered by Discuz! 7.2