返回列表 发帖

Discuz!X3.3+OPcache+伪静态

笺注:这是在 LNMP一键安装包(lamp_CentOS6.9) 的基础上进行。


OPcache的安装可参考:Discuz!X2.5+OPcache+伪静态

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的缓存功能:

在没有DNS服务器解析域名的情况下,可以在文件/etc/hosts里绑定:
[root@localhost ~]# tail -1 /etc/hosts
192.168.168.130 www.zhuohua.store bbs.zhuohua.store

[root@localhost ~]# ab -n 1000 -c 100 http://bbs.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 bbs.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:        bbs.zhuohua.store
Server Port:            80

Document Path:          /forum.php
Document Length:        12936 bytes

Concurrency Level:      100
Time taken for tests:   5.482 seconds
Complete requests:      1000
Failed requests:        0
Write errors:           0
Total transferred:      13747000 bytes
HTML transferred:       12936000 bytes
Requests per second:    182.41 [#/sec] (mean)
Time per request:       548.228 [ms] (mean)
Time per request:       5.482 [ms] (mean, across all concurrent requests)
Transfer rate:          2448.76 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    2   7.4      0      26
Processing:    17  517 103.1    535     698
Waiting:        9  513 102.4    529     698
Total:         36  520  97.5    535     698

Percentage of the requests served within a certain time (ms)
  50%    535
  66%    549
  75%    560
  80%    565
  90%    581
  95%    606
  98%    629
  99%    665
100%    698 (longest request)

笺注:可以看到OPcache的缓存功能启用后,每秒最大处理请求次数为182.41次,每个请求响应时间是5.482毫秒。





在PHP配置文件中关闭OPcache的缓存功能:
[root@localhost ~]# vi /usr/local/php/etc/php.ini
加上:  opcache.enable=0
图片1.png
2021-2-27 10:56



图片2.png
2021-2-27 10:56



再次测试:
[root@localhost ~]# ab -n 1000 -c 100 http://bbs.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 bbs.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:        bbs.zhuohua.store
Server Port:            80

Document Path:          /forum.php
Document Length:        12936 bytes

Concurrency Level:      100
Time taken for tests:   24.128 seconds
Complete requests:      1000
Failed requests:        999
   (Connect: 0, Receive: 0, Length: 999, Exceptions: 0)
Write errors:           0
Total transferred:      12965786 bytes
HTML transferred:       12253683 bytes
Requests per second:    41.45 [#/sec] (mean)
Time per request:       2412.824 [ms] (mean)
Time per request:       24.128 [ms] (mean, across all concurrent requests)
Transfer rate:          524.78 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    1   3.4      0      12
Processing:    46 2372 631.9   2416    3839
Waiting:       21 2308 609.5   2325    3698
Total:         46 2373 629.6   2416    3839

Percentage of the requests served within a certain time (ms)
  50%   2416
  66%   2632
  75%   2765
  80%   2859
  90%   3063
  95%   3199
  98%   3368
  99%   3482
100%   3839 (longest request)

笺注:可以看到OPcache的缓存功能没有启用时,每秒最大处理请求次数为41.45次,每个请求响应时间是24.128毫秒。





在PHP配置文件中再次启用OPcache的缓存功能:
[root@localhost ~]# vi /usr/local/php/etc/php.ini
修改:  opcache.enable=1
图片3.png
2021-2-27 10:57



图片4.png
2021-2-27 10:57



再次测试:
[root@localhost ~]# ab -n 1000 -c 100 http://bbs.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 bbs.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:        bbs.zhuohua.store
Server Port:            80

Document Path:          /forum.php
Document Length:        12936 bytes

Concurrency Level:      100
Time taken for tests:   5.428 seconds
Complete requests:      1000
Failed requests:        0
Write errors:           0
Total transferred:      13748152 bytes
HTML transferred:       12936000 bytes
Requests per second:    184.23 [#/sec] (mean)
Time per request:       542.812 [ms] (mean)
Time per request:       5.428 [ms] (mean, across all concurrent requests)
Transfer rate:          2473.40 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    1   2.5      0       9
Processing:    24  521 106.9    483     961
Waiting:       22  515 105.8    477     961
Total:         31  521 108.4    483     961

Percentage of the requests served within a certain time (ms)
  50%    483
  66%    515
  75%    538
  80%    559
  90%    651
  95%    762
  98%    894
  99%    935
100%    961 (longest request)

笺注:可以看到OPcache的缓存功能再次启用后,每秒最大处理请求次数为184.23次,每个请求响应时间是5.428毫秒。













#############
#############

Discuz!是采用PHP语言开发的,动态地址不利于蜘蛛抓取,开启伪静态有利于SEO优化。
其实Discuz!不开启伪静态,也是可以进行蜘蛛抓取的。

Discuz!X3.3开启伪静态:

管理中心》全局》SEO设置》URL静态化:
图片5.png
2021-2-27 10:59


图片6.png
2021-2-27 10:59

注释:全选。


图片7.png
2021-2-27 10:59



提交后,点击右上角的 查看当前的Rewrite规则
图片8.png
2021-2-27 11:00



复制这一段代码:(站点Discuz!使用的是Apache基于域名的虚拟主机,所以这里选择Apache Web Server(虚拟主机用户)
图片9.png
2021-2-27 11:00



笺注:也有Nginx的Rewrite规则:
图片10.png
2021-2-27 11:01



在Discuz!的站点目录下,创建伪静态规则文件:( .htaccess
[root@localhost ~]# cd /www/bbs.zhuohua.store/
[root@localhost bbs.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 ^(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 bbs.zhuohua.store]# ll .htaccess
-rw-r--r-- 1 root root 1312 2月  26 20:32 .htaccess


保存后,重启一下Apache:
[root@localhost ~]# service httpd restart
restart apache...  done


测试:

伪静态开启后,也不是说所有URL的表现形式都显示为静态页面:
图片11.png
2021-2-27 11:01



图片12.png
2021-2-27 11:02




板块、文章的URL的表现形式都显示为静态页面:
图片13.png
2021-2-27 11:02



图片14.png
2021-2-27 11:02






相关文章:
UPUPW_Ap5.6_XCache/OPCache+ionCube Loader

返回列表